0

$res stores result query and function output.

When I write

print_r($res);

then output is :

Array ( [0] => Array ( [@out] => 50 [0] => 112 ) ) 

Now, I want to print values 112 and 50.
And I want to store that value in another variable.

1
  • $var1 = $res[0][0]; $var2 = $res[0]['@out']; Commented Feb 21, 2014 at 7:31

5 Answers 5

2

Simple

echo $res[0]['@out'];
echo $res[0]['0'];
Sign up to request clarification or add additional context in comments.

Comments

0

You use ..

1st [0] is the index number and '@out' is ID .

That type of result got only on stored procedures...

$val = $res[0]['@out']; $val2 = $res[0]['0'];

echo $val; // to print value 50

echo $val2; // to print value 112

Comments

0

Try:

/* To store in other variables */  
$out_value = $res[ 0 ][ '@out' ];  
$zero_indexed_value = $res[ 0 ][ '0' ];  

/* To print */  
print_r( $out_value );  
print_r( $zero_indexed_value );

Comments

0

Your array is multidimensional array.so for storing values in to another variable and if you know the keys of the array use this

$value1 = $res[0]['@out'];
$value2 = $res[0]['0'];

to print try this

echo $value1;

echo $value2;

Comments

0

Access the array values by keys like the following.

/* Your array */
$res = array(
   "0" => array(
      "@out" => "50",
      "0" => "112"
   )
);

/* Returns 50 */
echo $res['0']['@out'];

/* Returns 112 */
echo $res['0']['0'];

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.