ok I got this array from the facebook API:
["affiliations"]=>
array(2) {
[0]=>
array(5) {
["nid"]=>
string(8) "16779497"
["name"]=>
string(11) "RWTH Aachen"
["type"]=>
string(7) "college"
["status"]=>
string(9) "Undergrad"
["year"]=>
string(1) "0"
}
[1]=>
array(5) {
["nid"]=>
string(8) "67109293"
["name"]=>
string(10) "Luxembourg"
["type"]=>
string(6) "region"
["status"]=>
string(0) ""
["year"]=>
string(1) "0"
}
}
now i wrote a function split_vars() that should write the value of
nid, name, type, status and year into one variable. since there are
more than one arrays (2 in this case) it would be good if i could have
the number of the array in the name of the variable so that
$affiliations_1_name should echo "Luxembourg".
I wrote this:
function split_vars(){
//This is just a part of the function, $user_info is the "big" array
where all the user_info data is
global $user_info, $affiliations, ${'affiliations_'.$i.'_nid'}, $
{'affiliations_'.$i.'_name'}, ${'affiliations_'.$i.'_type'}, $
{'affiliations_'.$i.'_status'}, ${'affiliations_'.$i.'_year'};
for($i=0;$i<count($user_info[0]['affiliations']);$i++){
$affiliations = $user_info[0]['affiliations'][$i];
${'affiliations_'.$i.'_nid'} = $affiliations['nid'];
${'affiliations_'.$i.'_name'} = $affiliations['name'];
${'affiliations_'.$i.'_type'} = $affiliations['type'];
${'affiliations_'.$i.'_status'} =
$affiliations['status'];
${'affiliations_'.$i.'_year'} = $affiliations['year'];
}
}
and outside of the variable I need to echo all these variable
variables.
But I get a Parse error: syntax error, unexpected ',' in line where
globals are declared.
On 8 Jun., 02:10, Simon COURTOIS <[EMAIL PROTECTED]> wrote:
> Dave wrote On 06/08/2008 01:47 AM:
>
> > On 7 Jun., 23:09, HappyNoff <[EMAIL PROTECTED]> wrote:
>
> >> On Jun 7, 9:54 pm, Dave <[EMAIL PROTECTED]> wrote:
>
> >>> Hi guys,
>
> >>> first post :)
> >>> my question: is it possible to have dynamic variable names, I mean
> >>> something like this:
>
> >>> for($i=0;$i<x;$i++){
> >>> $y_$i = blabla;
> >>> }
>
> >>> in other words I want the number of the loop to be displayer in the
> >>> name of the variable.
>
> >>> Thanks for help.
>
> >> Hi,
>
> >> You can test this syntax :
>
> >> $y = 'test';
>
> >> for($i=0; $i < 3; $i++)
> >> {
> >> ${$y.'_'.$i} = 'blabla';
>
> >> }
>
> >> echo $test_0;
>
> >> it should echo : blabla
>
> >> voila :)
>
> > merci
>
> > but how do I declare these as global variables?
> > I tried:
>
> > global ${$y.'_'.$i};
>
> > but I got a Parse error: syntax error, unexpected ',
>
> It depends on context... where do u want to declare this variables ? and
> where do you want to use it ?
>
> Understand that when you type : ${$y.'_'.$i}
> It's just a replacement.
>
> If $y = 'test' and $i = '0', it's exactly like if you had
> ${'test'.'_'.'0'}, or ${'test_0'} or $test_0...
>
> Is your 'global' call in a function that needs previously declared
> variables ?
>
> To help you, I need to understand what you wanna do and what you need ;)
>
> --
> Simon COURTOIS
> {EPITECH.} tek4 | (LINAGORA) Developer | [ADITAM] Project Manager
> 10, rue Brillat-Savarin 75013 Paris | 01 45 42 72 30 - 06 72 44 67
> 81http://www.happynoff.fr
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---