Jump to content

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 ; )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.