Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

pulling values out of arrays and into strings

Posted on 2011-09-09
6
Medium Priority
?
250 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
[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
6 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 2000 total points
ID: 36515122
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
ID: 36515172
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
ID: 36515182
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
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!

 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36515186
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
ID: 36515206
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
ID: 36515217
You are welcome!  Best of luck to you on your project.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

722 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