Dave wrote On 06/08/2008 02:33 AM:
> ok I got this array from the facebook API:
>
> [...]
>
> 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.
>   
Ok there is the thing.

with php you don't declare a global variable with global $var. when you 
use global you say 'I wanna use this $var in my function even if it has 
been declared in superior scope'.
For example :

function say_hello()
{
    global $hello;
    echo $hello;
}

say_hello();
$hello = 'hi';
say_hello();

This script will echo nothing and hi, because the second time the 
variable has a value.
I think you see this in a C/C++ way. That's not PHP's way.

another thing. when you write global ${'affiliations_'.$i.'_nid'}, it 
can't be good, $i is not even declared at this point.

-- 
Simon COURTOIS
{EPITECH.} tek4 | (LINAGORA) Developer | [ADITAM] Project Manager
10, rue Brillat-Savarin 75013 Paris | 01 45 42 72 30 - 06 72 44 67 81
http://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 cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to