0

I am new to arrays and i'm trying to display a certain few.

I've tried var_dump and here's my results

array(6) { 
["show_hero_options"]=> string(1) "1" 
["hero_height"]=> string(5) "600px" 
["hero_width"]=> string(4) "100%" 
["hero_buttons"]=> string(4) "show" 
["upload_zzz_link_1"]=> string(105) "http://blahblah.com/image_link.png" 
["upload_zzz_link_2"]=> string(105) "http://blahblah.com/image_link2.png" 
["upload_yyy_link_1"]=> string(79) "http://blahblah.com/image_link3.png"
}

Basically I only want to display the values of string 105.

How can I do this?

UPDATE: Sorry to mess you all around, i've just figured out I can't seems to use the string as this seems to change, see this var_dump

array(9) { 
["show_hero_options"]=> string(1) "1" 
["hero_height"]=> string(5) "600px" 
["hero_width"]=> string(4) "100%" 
["hero_buttons"]=> string(4) "show" 
["upload_zzz_link_1"]=> string(105) "http://www.blahblah.com/image_link.jpg" 
["upload_zzz_link_2"]=> string(79) "http://www.blahblah.com/image_link.jpg" 
["upload_zzz_link_3"]=> string(79) "http://www.blahblah.com/image_link.jpg" 
["upload_yyy_link_1"]=> string(79) "http://www.blahblah.com/image_link.jpg" 

}

Basically I want to display all the zzz images, can I do this by and ID or classname?

2
  • Do you want it to display exactly as above, just with fewer entries? Commented Jul 8, 2014 at 8:49
  • Hi, i've just updated the question, basically I want to display the zzz images? Commented Jul 8, 2014 at 9:01

4 Answers 4

1

This will display every value from the array if the key is 'upload_zzz_link_1' or the length of the value is equal to 105

foreach($your_array as $key => $value) {
    if($key == 'upload_zzz_link_1') {
        echo $value;
    } elseif(strlen($value) == 105) {
        echo $value;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0
echo $array["upload_zzz_link_1"];

Replace $array with the name of your array.

Comments

0

Just try with:

$yourArray['upload_zzz_link_1']

105 is a length of the string. So if you want to display strings with length equals 105, use:

foreach ($yourArray as $value) {
  if (strlen($value) != 105) {
    continue;
  }

  var_dump($value);
}

1 Comment

Thanks, that did work but i realised my strings have changed, basically I want to display all the zzz images.
0

Store the array in a variable:

$array = array('your' => 'values');

and you can get the value by using its key

Like that:

echo $array["upload_zzz_link_1"];

OR

You can also try using foreach loop with key value pair

foreach($array as $key => $value) {
    if($key == 'upload_zzz_link_1') {  // check here the key which of the value you want
        echo $value;
    } 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.