how do i get only values from var dump array?

user2249079 picture user2249079 · Apr 12, 2013 · Viewed 13.5k times · Source

Is it possible to escape array(1) { [0]=> string(12)} from var_dump($variable) because I want to show only values from var_dump and except array string?

Testing Code

 <?php
 $array = array(
 "foo" => "bar",
 "bar" => "foo",
 100   => -100,
-100  => 100,
 );
 var_dump($array);
 ?>

now results will be like this

array(4) {
["foo"]=>
string(3) "bar"
["bar"]=>
string(3) "foo"
[100]=>
int(-100)
[-100]=>
int(100)
}

But I want to get only bar and foo values except string(3) and array(4)?

Answer

PlantTheIdea picture PlantTheIdea · Apr 12, 2013

Right here:

foreach ($array as $key => $value){
    echo $key.'=>'.$value."\n";
}

For each key-value pair, this will echo the items as desired.