Jump to content

Append every value in an array


macwise

Recommended Posts

Though I've been tinkering with PHP for a number of years, I'm mostly a front end developer/designer (HTML5, XHTML, CSS).  In other words, please go easy on me. :)

 

I am working on a site where we're pulling data from mysql.  Each row that has a column for dimensions which look like this: 20x10x5

 

Here's what I have so far:

$dimensions = explode("x",$row['DIMENSIONS']);

$x_separated = implode("x", $dimensions);

echo "$x_separated";

 

What I would like to do is append an "inches" or "in" to each value in the array.  The resulting values should look like this:

    [0] => 20in

    [1] => 10in

    [2] => 5in

 

And after the implode, would then look like this: 20in x 10in x 5in

 

Any help from the more experienced coders here is much appreciated.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/212116-append-every-value-in-an-array/
Share on other sites

Thanks, ldb358!  That worked perfectly!

 

Here is the resulting code, for anyone with the same problem:

 

$dimensions = explode("x",$row['DIMENSIONS']);
foreach($dimensions as $key => $value){
   $dimensions[$key] = $value ."in";
}
$x_separated = implode(" x ", $dimensions);
echo "$x_separated";

Thanks, ldb358!  That worked perfectly!

 

Here is the resulting code, for anyone with the same problem:

 

$dimensions = explode("x",$row['DIMENSIONS']);
foreach($dimensions as $key => $value){
   $dimensions[$key] = $value ."in";
}
$x_separated = implode(" x ", $dimensions);
echo "$x_separated";

 

Thx for sharing ; )

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.