can some one explain...

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

can some one explain...

Post by Torniquet »

all this in a little detail

Code: Select all

$act = $_GET['act'];
$acts = array('create_cat', 'create_subcat');
$actions = array('create_cat' => 'Create Catagory', 'creat_subcat ' => 'Create Sub Catagory');

foreach($actions AS $url => $link){
	echo "<a href='admin.php?act=" . $url . "'>" . $link . "</a>";
}
obviously i know what is happening on the first 2 lines...

but can someone please explain whats happening with everything else?

i have seen the outcome, but i am confused about the '=>' and how $url and $link become values.

Thanks xxx
New Site Coming Soon! Stay tuned :D
User avatar
KunoNoOni
Posts: 61
Joined: Sun May 09, 2010 1:54 am

Re: can some one explain...

Post by KunoNoOni »

Think of it like a function. when you pass a variable into a function it has one name and in the function it has a different name. for example

Code: Select all

b = 2;
c = 3;
a = addnumbers(2,3);
function addnumbers(d,e)
{
     return d+e;
}
I hope this makes sense. And I hope I explained it right :lol:

KunoNoOni
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: can some one explain...

Post by Torniquet »

KunoNoOni wrote:Think of it like a function. when you pass a variable into a function it has one name and in the function it has a different name. for example

Code: Select all

b = 2;
c = 3;
a = addnumbers(2,3);
function addnumbers(d,e)
{
     return d+e;
}
I hope this makes sense. And I hope I explained it right :lol:

KunoNoOni

sorry... but no that didnt help what so ever :(

thnx for tryin to explain though :D
New Site Coming Soon! Stay tuned :D
User avatar
KunoNoOni
Posts: 61
Joined: Sun May 09, 2010 1:54 am

Re: can some one explain...

Post by KunoNoOni »

Ok let me try again. Think the terms of association. Hand is to glove as Head is to hat. There both things that you wear. so Create Category is to URL as Create Sub Category is to Link.


Does that make sense?


-KunoNoOni
Jony
Posts: 26
Joined: Tue May 11, 2010 3:34 pm

Re: can some one explain...

Post by Jony »

$url and $link do not become values, they are variables that contain values.

foreach loops the array $actions and assigns the values from 'create_cat' and 'Create Catagory' into $url and $link then prints, then does the same for 'create_subcat' and 'Create Subatagory'

inside the array $actions 'creat_cat' is the key and 'Creat Catagory' is the value contained in the key.

both 'create_cat' and 'Create Catagory' are constants.

That's how i understand this code. I may be wrong.

So,for this example, you will have 2 prints:

Create Catagory - > links to something(creat_cat)
Creat Subcatagory -> links to something(create_subcat)

where something may be a function from admin.php
Last edited by Jony on Sat May 15, 2010 10:15 pm, edited 1 time in total.
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: can some one explain...

Post by Torniquet »

so in the $actions array... it is setting 'create_cat' as the key, then 'creat catagory' as the value of the key? by using the '=>' sign?

and then in the foreach.. its obviously taking each array value from $actions, and says that $url has a value of 'create_cat' and $link has a value of 'Create catagory' again by using the => sign? so it would be like syaing $url is the key and $link is the value of the key?

am i close with this now? lol
New Site Coming Soon! Stay tuned :D
Jony
Posts: 26
Joined: Tue May 11, 2010 3:34 pm

Re: can some one explain...

Post by Jony »

Torniquet wrote:so in the $actions array... it is setting 'create_cat' as the key, then 'creat catagory' as the value of the key? by using the '=>' sign?

and then in the foreach.. its obviously taking each array value from $actions, and says that $url has a value of 'create_cat' and $link has a value of 'Create catagory' again by using the => sign? so it would be like syaing $url is the key and $link is the value of the key?

am i close with this now? lol
That's how i read it.
Obviously, i cannot know how the 'create_cat' value is worked with in admin.php.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: can some one explain...

Post by Jackolantern »

Torniquet wrote:so in the $actions array... it is setting 'create_cat' as the key, then 'creat catagory' as the value of the key? by using the '=>' sign?

and then in the foreach.. its obviously taking each array value from $actions, and says that $url has a value of 'create_cat' and $link has a value of 'Create catagory' again by using the => sign? so it would be like syaing $url is the key and $link is the value of the key?

am i close with this now? lol
Yep, that is how it is working. The 3rd line is creating arbitrary value and key pairs, and then the foreach construct is giving them abritrary handlers to use within its block for iteration :)
The indelible lord of tl;dr
Post Reply

Return to “Coding”