Reputation: 51
$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.
Upvotes: 0
Views: 68
Reputation: 3847
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'];
Upvotes: 0
Reputation: 3106
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
Upvotes: 0
Reputation: 4089
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;
Upvotes: 0
Reputation: 24002
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 );
Upvotes: 0