tags:

views:

217

answers:

6

I got a question about the "$key => $value" in the code below... I looked it up in google but it didn't returned any results.. All I know is that "=>" is used in arrays like x = array('a' => 'b').

function _stripslashes_rcurs($variable,$top = true)
 {
  $clean_data = array();
  foreach($variable as $key => $value)
  {
   $key = ($top) ? $key : stripslashes($key);
   $clean_data[$key] = (is_aray($value)) ?
    stripslashes_rcurs($value, false) : stripslashes($value);
  }
  return $clean_data;
 }

thank you for your help

A: 

It's just accessing the key and value of the array (all PHP arrays are really dictionaries/hash maps) simultaneously.

Matthew Flaschen
+13  A: 

Basically it's looping through $variable and setting the key as $key and the value as $value. So let's say this is your arrray:

$variable = array(
  'a' => 'A'
  'b' => 'B'
  'c' => 'C'
);

Then in each iteration of the loop, $key would be one of the lowercase letters, and $value would be the corresponding uppercase letter.

musicfreak
+1 good easy explanation :)
alex
A: 

ya its an array...

$key => $val

its for the index and the value of the array

+1  A: 

Key / Value is referring to the index of the array, and the value in said index. If you have an array like this:

$myArray = array("index0","index1","index2");

the "foreach" goes through the entire array. The "key" is the current index its on. So the first time through the loop, the key = 0 and the value = "index0"... next time through, the key = 1 and value = "index1"... get it?

micmoo
+3  A: 

"$key => $value" ... I looked it up in google but it didn't returned any results

The most important advice for you is to become familiar with the documentation at www.php.net . In your case you would look at "foreach" in the "function list". This documentation is considered by many to be the best example any language has so far.

gbarry
A: 

The your call to (presumably) is_array() function has a small typo.

not: is_aray()
but: is_array()

http://nl.php.net/manual/en/function.is-array.php

php.net helped me out more than once :)

M4rk