[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Php Array display issue (syntax?)

Posted on 2011-03-02
9
Medium Priority
?
222 Views
Last Modified: 2012-05-11
Hi all,

I have this array which contains the info when I use:

var_dump($myArray);

Ths above works fine BUT when I did this:

echo $myArray[0];  

I just get the word Array and no result ... what am I doing wrong please?

Thanks


0
Comment
Question by:error77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 35017976
I should know how is created this array but try this

echo $myArray[0][0]

Maybe your array is build as an array of array... Try to post the output of var_dump, please

Cheers
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35018002
As an example:

$c=array("tt");
echo $c[0];

Open in new window


outputs "tt"

Can you show your output?
0
 

Author Comment

by:error77
ID: 35018069
This is the output of the var_dump


array(1) { [0]=> array(7) { ["uid"]=> string(15) "112211133322" ["name"]=> string(21) "my name" ["pic"]=> string(77) "http://pro.com/34544544545.jpg" ["is_app_user"]=> string(1) "1" ["birthday_date"]=> string(0) "" ["sex"]=> string(4) "male" ["email"]=> string(0) "" } }


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
darren-w- earned 2000 total points
ID: 35018134
You will need to do something like:

echo [0]["uid"]
echo [0]["name"]
echo [0]["pic"]

etc...
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35018161
or something like

for each ($myArray[0] as  $key => $value ){
echo $key." :".$value;
}
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35018244
This is right: your $myArray contains an array inside, having 7 keys with values (an array inside an array).
0
 

Author Closing Comment

by:error77
ID: 35018310
Thanks
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 35018476
Think you should split points... Without knowing your output I've shown you the probelm and the solution (changing the index type accordingly): don't you agree?
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35018646
I agree,

my example is incorrect it should read:

echo $myArray[0]["uid"]
echo $myArray [0]["name"]
echo $myArray[0]["pic"]
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question