0

I know how to perform a normal foreach loop but I can't seem to work it for an array returned by the vafpress framework. I am using var_dump(vp_metabox('vp_meta_sample_2.binding_group')); which is generating the below mentioned array. How can I loop through all the images!

(1) { [0]=> array(4) { ["name"]=> string(1) "1" ["url"]=> string(10) "234234.com" ["image"]=> string(62) "http://localhost/wp/wp-content/uploads/2014/02/bottomright.jpg" ["shortcode"]=> string(108) "[shortcode name="1" url="234234.com" image="http://localhost/wp/wp-content/uploads/2014/02/bottomright.jpg"]" } }

I am using the following loop to get the values

$age=print_r (vp_metabox('vp_meta_sample_2.binding_group'));
                print_r ($age);
foreach($age as $x=>$x_value)
   {
   echo "Key=" . $x . ", Value=" . $x_value;
   echo "<br>";
   }

2 Answers2

0

In this statement:

$age=print_r (vp_metabox('vp_meta_sample_2.binding_group'));

from the code above, $age will be empty since print_rdoes not return anything.

Proper:

    $age= vp_metabox('vp_meta_sample_2.binding_group');
Axel Amthor
  • 10,980
  • 1
  • 25
  • 44
  • ok i remove the print_r but can you tell me how to loop this output array(1) { [0]=> array(4) { ["name"]=> string(1) "1" ["url"]=> string(10) "234234.com" ["image"]=> string(62) "http://localhost/wp/wp-content/uploads/2014/02/bottomright.jpg" ["shortcode"]=> string(108) "[shortcode name="1" url="234234.com" image="http://localhost/wp/wp-content/uploads/2014/02/bottomright.jpg"]" } } – user2976690 Feb 19 '14 at 16:31
  • look at [this link](http://stackoverflow.com/questions/10057671/how-foreach-actually-works) – Axel Amthor Feb 20 '14 at 07:32
0

Try this, without print_r()

$age=vp_metabox('vp_meta_sample_2.binding_group');

instead of

$age=print_r (vp_metabox('vp_meta_sample_2.binding_group'));
Krish R
  • 22,583
  • 7
  • 50
  • 59