Heim > Backend-Entwicklung > PHP-Tutorial > 关于多维数组的一个问题,

关于多维数组的一个问题,

WBOY
Freigeben: 2016-06-23 13:50:39
Original
868 Leute haben es durchsucht

<?php	$class = [		"group1" => [			["name"=>"zs","age"=>"10","sex"=>"nan"],			["name"=>"ls","age"=>"11","sex"=>"nan"],			["name"=>"ww","age"=>"12","sex"=>"nv"]		],		 [			["name"=>"zs","age"=>"10","sex"=>"nan"],			["name"=>"ls","age"=>"11","sex"=>"nan"],			["name"=>"ww","age"=>"12","sex"=>"nv"]		],		 [			["name"=>"zs","age"=>"10","sex"=>"nan"],			["name"=>"ls","age"=>"11","sex"=>"nan"],			["name"=>"ww","age"=>"12","sex"=>"nv"]		]	];	echo '<pre class="brush:php;toolbar:false">';	print_r( $class );	echo '
Nach dem Login kopieren
';?>
这个老是不对啊,求解。
Parse error: syntax error, unexpected '[' in D:\program files\wamp\www\text.php on line 3


回复讨论(解决方案)

你这个定义 的是什么?数组吗? 按你的思路应该这样定义。

$class =array(  "group1" => (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
           ("name"=>"ww","age"=>"12","sex"=>"nv")
        ), 
         (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
           ("name"=>"ww","age"=>"12","sex"=>"nv")
        ), 
        (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
            ("name"=>"ww","age"=>"12","sex"=>"nv")
        )
    )) ;
     

你这个定义 的是什么?数组吗? 按你的思路应该这样定义。

$class =array(  "group1" => (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
           ("name"=>"ww","age"=>"12","sex"=>"nv")
        ), 
         (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
           ("name"=>"ww","age"=>"12","sex"=>"nv")
        ), 
        (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
            ("name"=>"ww","age"=>"12","sex"=>"nv")
        )
    )) ;
     


额,书上说不是要尽量用[]吗?书上array也没写啊。

你的代码要求 php >= 5.4


你这个定义 的是什么?数组吗? 按你的思路应该这样定义。

$class =array(  "group1" => (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
           ("name"=>"ww","age"=>"12","sex"=>"nv")
        ), 
         (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
           ("name"=>"ww","age"=>"12","sex"=>"nv")
        ), 
        (
            ("name"=>"zs","age"=>"10","sex"=>"nan"),
            ("name"=>"ls","age"=>"11","sex"=>"nan"),
            ("name"=>"ww","age"=>"12","sex"=>"nv")
        )
    )) ;
     


额,书上说不是要尽量用[]吗?书上array也没写啊。
都可以,但用[]也是这样的
$class['group1'][]=array("name"=>"zs","age"=>"10","sex"=>"nan");
$class['group1'][]=array("name"=>"ls","age"=>"11","sex"=>"nan");
$class['group1'][]=array("name"=>"ww","age"=>"12","sex"=>"nv");
.
.
.

你的代码要求 php >= 5.4


这样啊,长知识了,谢谢版主
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage