在php中定义一个数组数组

时间:2015-11-07 11:36:24

标签: php arrays

我在php中定义了一个像这样的数组

<?php

$Category = array("Apparel","Grocery","Health","Gift","Footwear","Jewelry","Food & Bev");
$Shops = array("Giny & Jony","Big Bazaar","Health & Glow","Factory Outlet Store","Archies","Bata","100 Rs Shop","Silver Touch","Sri Devi Traders","Avatar","Steamzz");
$Type = array($Category,$Shops); 

echo $Type[0];


?>

当我尝试打印时,它说“错误:无法将数组转换为字符串” 这种宣告方式是否正确?如果没有,你能否分享你的观点。

3 个答案:

答案 0 :(得分:2)

它不能回显$Type[0],因为它是一个数组。可以使用print_r()打印数组。

$Category = array("Apparel","Grocery","Health","Gift","Footwear","Jewelry","Food & Bev");
$Shops = array("Giny & Jony","Big Bazaar","Health & Glow","Factory Outlet Store","Archies","Bata","100 Rs Shop","Silver Touch","Sri Devi Traders","Avatar","Steamzz");
$Type = array($Category,$Shops); 

print_r($Type[0]);

答案 1 :(得分:0)

如果你想调试变量,看看它们是什么样的,一个简单的解决方案可能是var_dump em。

var_dump($Type[0]);

但是你没有做错任何事情,除非你不能回应array这是一个合法的印刷声明作为一个例子。

echo $Type[0][0];

答案 2 :(得分:0)

试试看结果 -

<?php

$Category = array("Apparel","Grocery","Health","Gift","Footwear","Jewelry","Food & Bev");
$Shops = array("Giny & Jony","Big Bazaar","Health & Glow","Factory Outlet Store","Archies","Bata","100 Rs Shop","Silver Touch","Sri Devi Traders","Avatar","Steamzz");
$Type = array($Category,$Shops); 

var_dump($Type);


?>