-1

I have defined an array in php like this

<?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];


?>

When i am trying to print, it says "Err:Cannot convert array into string" Is this way of declaring is correct?? If not,can you share your views.

Rasik Suhail
  • 206
  • 1
  • 2
  • 8

3 Answers3

2

It can't echo $Type[0] because it is an array. Array's can be printed using 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]);
Thaillie
  • 1,362
  • 3
  • 17
  • 31
0

If you want to debug you variables, to see what they look like, a simple solution could be to var_dump em.

var_dump($Type[0]);

But you are not doing anything wrong, except you can't echo an array this is an legal print statement as an example.

echo $Type[0][0];
mrhn
  • 17,961
  • 4
  • 27
  • 46
0

try it and see result -

<?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);


?>
Manoj Salvi
  • 2,639
  • 1
  • 17
  • 21