Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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.

share|improve this question
    
echo $matches[0][0]; –  techycommerce Jan 7 '13 at 16:51
    
thanks....works fine –  FAAD Jan 7 '13 at 16:51
1  
ok i will...... –  FAAD Jan 7 '13 at 16:54
    
Extract won't work here since numbers aren't valid variable names. $1 $2 etc are not valid. variables must begin with a letter or underscore. –  Colin M Jan 7 '13 at 16:55
    
@Colin - extract will allow you to prefix the variable names –  Mark Baker Jan 7 '13 at 16:57

2 Answers 2

up vote 2 down vote accepted

Its multi-dimensional array: Try:

 echo $matches[0][0];
 echo $matches[0][1];
share|improve this answer

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'];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.