tags:

views:

80

answers:

6
Array ( [0] => Array ( [OPT] => 65 ) )

how to get 65 to a variable in PHP

help me please....

+2  A: 
$arr = array(array('OPT'=>65)); // the array
echo $arr[0]['OPT'];            // will print 65
codaddict
+3  A: 
$variable = $arrayname[0]['OPT'];

there are plenty of useful information for the beginners in the official manual.

SilentGhost
+5  A: 

In all simplicity:

$foo = array(array('opt'=>65));
$bar = $foo[0]['OPT'];

I suggest you familiarize yourself with the basics of PHP and the excellent language reference provided by PHP.net.

nikc
A: 
$var=$arr[0]['OPT'];

To know more about array see this

MAS1
A: 

To prevent warnings, get value only if $arrayname[0]['OPT'] exists. If not - $variable will store default value - 0.

$variable = isset($arrayname[0]['OPT'])?$arrayname[0]['OPT']:0;
Anatoly Orlov
Suggesting an inline conditional to someone who doesn't know how to reference an array value? This is a little brutal.
Austin Fitzpatrick
I dont think so. I also started with simple questions and learned many new things along the way
Anatoly Orlov
A: 

Try this:

<?php 

$test= array ('0' => Array ( 'OPT' => 65 ) );
foreach($test as $val1) {
   foreach($val1 as $val2) {
       echo $val2;
       }
    }
?>
Murali Krishna kilari