Solved

How would I retrieve the members of this array one at a time?

Posted on 2015-02-24
5
84 Views
Last Modified: 2015-02-24
When I do a print_r(array_values($array));, I get this:

Array ( [0] => Array ( [0] => 3 [id] => 3 [1] => Weekly Reports [name] => Weekly Reports [2] => Nelson Del Valle [author] => Nelson Del Valle [3] => nelson.delvalle@verizonwireless.com [email] => nelson.delvalle@verizonwireless.com [4] =>
Authored by Nelson Del Valle, this is a collection of graphs and tables that reflect the status and progress of several metrics crucial to Verizon's commitment to quality control
 [description] =>
Authored by Nelson Del Valle, this is a collection of graphs and tables that reflect the status and progress of several metrics crucial to Verizon's commitment to quality control
 [5] => http://southareanetwork.nss.vzwnet.com/weekly_reports/index.php [url] => http://southareanetwork.nss.vzwnet.com/weekly_reports/index.php ) )

If I wanted to be able to grab just the id or just the email, how do I do it? I was thinking something along the lines of "echo $array[0] but that's not working.

How do I do it?
0
Comment
Question by:brucegust
[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
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 333 total points
ID: 40628417
You have a multi-dimensional array, so it would be $array[0]["id"] or $array[0]["name"], etc...

If you had more than one record in your array, and you wanted to get the name of the 2nd record, it'd be $array[1]["name"].
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 167 total points
ID: 40628427
Your array seems the result of a query which returns database value in both associative and number indexed array.
If you're using PDO you can ue PDO::FETCH_ASSOC to get only an associative array

$result = $tmt->fetchAll($query, PDO::FETCH_ASSOC);

Open in new window


Anyway, to get email you can just use this:
echo $arr[0]['email'];

Open in new window

or this
echo $arr[0][3];

Open in new window

0
 
LVL 35

Assisted Solution

by:gr8gonzo
gr8gonzo earned 333 total points
ID: 40628430
Also, that output looks like it's the result of a mysql_fetch_array or mysqli_fetch_array call. IMHO, the _fetch_array leads to problems. You have more than one way to access the data, which can lead to inconsistent code (one piece of code uses the numeric indexes, while another piece of code might use the column names). It's better to pick one (associative is usually better) and use that instead. You should be able to replace _fetch_array with _fetch_assoc, for example, and it will just leave you with one set of data instead of two.
0
 

Author Comment

by:brucegust
ID: 40628443
Perfect! Thank, Gonzo!
0
 

Author Comment

by:brucegust
ID: 40628447
...and Marco!
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

756 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