PHP two-dimensional array, how to solve it

PHP two-dimensional array $str = array ( “Network Programming Book”=>array(‘a’,’d’,’er’), “History books”=>array(‘boko’,’fd’,’popo’), “Literature books”=>array(‘fd’,’fd’,’fd’), ); echo $str[0][2]; why not showing ——Solution——————–Of course it will not be displayed !There is no subscript 0, how to display it? ——Solution——————–Because you originally The position of 0 has been replaced by ‘Network Programming Book’ echo $str[‘Network Programming Book’][2]——Solution—————– —In your two-dimensional array, the outermost subscript of the associative array is a character, not a number——Solution- ——————You can change the code to $str = array (           array(‘a’,’d’,’er’),//Network programming books           array(‘boko’,’fd’,’popo’),//Historical books           array(‘fd’,’fd’,’fd’),//Literary books );           echo $str[0][2]; This will show

php two-dimensional array

Two-dimensional array PHP $name[0]= array(“1″=>”1111″,”2″=>”2222″,”3″ =>”3333” ); if (isset($name[0][“1”])) { echo “wancheng fuzhi “; echo $name[0][1].$name[0].$name[0 ; >Reply to discussion (solution) Precede with $name = array(); Precede with $name = array(); I understood it instantly. Thank you $name[0]= array(“1″=> “1111”,”2″=>”2222″,”3″=>”3333″); if (isset($name[0][1])) { echo “wancheng fuzhi “; echo $name[0] [2].$name[0].$name[0]; } else echo “fffffffffff”; PHP version? At least my 5.3.2 is running normally My running results are like this: wancheng fuzhi 1111ArrayArray I used the local PHP environment for testing, PHP version 5.4

php two-dimensional array, php two-dimensional associative array

php two-dimensional array, php two-dimensional associative array

List of contents of this article: 1. PHP two-dimensional array 2. How does PHP handle two-dimensional arrays? 3. PHP, how to define two-dimensional arrays 4. How does php define a two-dimensional array PHP two-dimensional array ?php $userinfo = array(‘name’=’pass’,’test’=’test’); $user = $_POST[‘user’ ]; $pass = $_POST[‘pass’]; if(empty($user) || empty($pass)) { // Show login form here } else { if(array_key_exists($user ,$userinfo)) { if($pass==$userinfo[$user]) header(‘location:main.php’) ; else echo ‘The password is incorrect’; } else echo ‘The user is not Exist’; } ? How does PHP handle two-dimensional arrays? It’s very simple Look at the following code //$a is a two-dimensional array $a = array(array(‘zhangsan’=20),array(‘zhangsan’ =3500),array(‘lish’=10)); foreach ($a as $key = $value) { foreach ($value as $k = $v ) { if ($b[$k]) { $b[$k]=$v+$b[$k]; } else{ $b[$k]=$v; } } } //$b is the synthesized one-dimensional array var_dump($b); //array (size=2) // ‘zhangsan ‘ = int 3520 // ‘lish’ = int 10 //handwritten Please adopt PHP, how to define a two-dimensional array ?php $list = array ( array(“a”,1,11), array(“b”,2,12), array(“b”,2,12), p> array(“c”,3,13), array(“d”,4,14) ); echo “name: “.$list[0][0].”: value1: “.$list[0][1].”, value11: “.$list[0][2].”.br”; echo “name: “.$list[1][0].”: value2: “.$list[1][1].”, value12: “.$list[1][2] .”.br”; echo “name: “.$list[2][0].”: value3: “.$list[2][1].”, value13: “.$ list[2][2].”.br”; echo “name: “.$list[3][0].”: value4: “.$list[3][1]. “, value14:…

PHP two-dimensional array, how to solve it

PHP two-dimensional array $str = array ( “Network programming books”=>array(‘a’,’d’,’er’), “Historical Books”=>array(‘boko’,’fd’,’popo’), “Literature Books”=>array(‘fd’,’fd’,’fd’), ); echo $str[0][2]; why not show ——Solution ———————Of course not displayed! There is no subscript 0, how to display it? ——Solution ——————–Because you originally The position of 0 is replaced by ‘Network Programming Books’ echo $str[‘Network Programming Books’][2]——Solution —————– —Your two-dimensional array, the outermost subscript of the associative array is a character, not a number——Solution- ——————-You can change the code to $str = array ( array(‘a’,’d’,’er’),//Network programming books array(‘boko’,’fd’,’popo’),//historical books array(‘fd’,’fd’,’fd’),//literary books ); echo $str[0][2]; This will show

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索