Solved

pulling values out of arrays and into strings

Posted on 2011-09-09
6
201 Views
Last Modified: 2012-05-12
I have an array like this:

print_r($GA); //provides these results

Array (
 [0] => Array ( [LABEL] => GAD ID [TYPE] => text [NAME] => GA_ID [VALUE] => 1707444616535 )
 [1] => Array ( [LABEL] => GAd 1 [TYPE] => text [NAME] => GA_1 [VALUE] => 6780673118 )
 [2] => Array ( [LABEL] => GAd 2 [TYPE] => text [NAME] => GA_2 [VALUE] => 3745034999 )
 )

I need to pull those VALUEs out as strings and have this :

$GA_ID = // the value of GA_ID
$GA_1 = // the value of GA_1
$GA_2 = // the value of GA_2

I'm not array-smart.  How is this done?

Thank you,                Chris

0
Comment
Question by:St_Aug_Beach_Bum
  • 4
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
Comment Utility
You would need to separate name, value pairs from the array first, then use extract:

foreach($GA as $array) {
     $newArray[$array['NAME']] = $array['VALUE'];
}
extract($newArray, EXTR_SKIP);

Open in new window

0
 

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
ah, ok, then I proceed like this?

echo $newArray['GA_ID'];

that's what seems to work from some quick experimenting
0
 
LVL 17

Expert Comment

by:OmniUnlimited
Comment Utility
No.  You asked to have variables like this:

$GA_ID = // the value of GA_ID
$GA_1 = // the value of GA_1
$GA_2 = // the value of GA_2

and that's what I gave you.  If you echo the values you will get the following:

echo $GA_ID; // displays 1707444616535
echo $GA_1; // displays 6780673118
echo $GA_2; // displays 3745034999

Isn't this what you asked for?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:OmniUnlimited
Comment Utility
If you actually wanted it to be in the $newArray['GA_ID'] format, simply get rid of the extract statement.
0
 

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
Ah, sorry, I got confused somewhere, the first time I tested it didnt' seem to work, and type on my part perhaps -

You do have it exactly as needed  :)  

Thank you,

Chris
0
 
LVL 17

Expert Comment

by:OmniUnlimited
Comment Utility
You are welcome!  Best of luck to you on your project.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now