0

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.

5
  • 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. Commented Jan 7, 2013 at 16:55
  • @Colin - extract will allow you to prefix the variable names Commented Jan 7, 2013 at 16:57
  • @MarkBaker True, but that's not being done here is it :D Commented Jan 7, 2013 at 16:58
  • @Colin, no, but it should be (though I'm unsure why OP doesn't not simply work with the array anyway) Commented Jan 7, 2013 at 16:59
  • @MarkBaker Yes, in this case it should be in order for this to work. However I also just generally think that extract is a terrible function and it's list of legitimate uses cases is virtually non-existent. Working with the array is definitely the preferred choice here. Commented Jan 7, 2013 at 17:01

2 Answers 2

2

Its multi-dimensional array: Try:

 echo $matches[0][0];
 echo $matches[0][1];
Sign up to request clarification or add additional context in comments.

Comments

0

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'];

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.