FAAD
FAAD

Reputation: 79

PHP extract array into variables

i have following output i am trying to put individual values into separate variables

output:

Array ( [0] => Array ( [0] => 8711 [1] => 200 [2] => 755 [3] => 1800 [4] => 01 [5] => 675 [6] => 8910 ) )

i have tried following code but no success.

echo extract($matches[0]);

please help me in this regard.

Upvotes: 0

Views: 2886

Answers (2)

a coder
a coder

Reputation: 7639

It helps to sometimes see the array in a more readable format.

Try

echo '<pre>' . print_r($matches) . '</pre>';

You can also specify:

echo '<pre>' . print_r($matches[0]) . '</pre>';

To limit data for that sub array.

If you just need to access one of your elements others have already shown how.

Ex.

$arr = array('a'=>'alphabet', 'b'=>'better', 'c'=>array(1=>'cat', 2=>'click', 'z'=>'clean'));

To put 'clean' in a variable you'd use:

$clean = $arr['c']['z'];

To put 'better' in a variable you'd use:

$better = $arr['b'];

Upvotes: 0

Vimalnath
Vimalnath

Reputation: 6463

Its multi-dimensional array: Try:

 echo $matches[0][0];
 echo $matches[0][1];

Upvotes: 2

Related Questions