[SUP]Hi, Can someone please tell me why my function is not getting the value of $content ? At least that's what appears to happen.... Another question. In the documentation for php functions I saw that frequently the symbol "&" is used before a parameter. As in: kaki(&$content) What doe the "&" stands for? and is it necessary because I have many other functions that work well without it. Thanks, $Array = array( //level 1: array( array(400, 300)), //level 2: array( array(500, 330), array(300, 330), array(330, 230),), // level 3: array( array(210, 400), array(210, 300),) ); function kaki($content) { preg_match("^L([0-9])^", $content, $match); $zLevel = $match[1]; $z = $zLevel; preg_match("^C([0-9])^", $content, $match); $zCircle = $match[1]; $l = $zCircle; $testx = $Array[$z-1][$l-1][0]; $testy = $Array[$z-1][$l-1][1]; echo "x of connected circle is: ".$testx."<br>"; echo "y of connected circle is: ".$testy."<br>"; } $content = 'L2C2'; kaki($content); PHP: [/SUP]
In simple terms, the "&" means you are passing $content as reference, meaning the value of $content outside the function gets updated when it is modified inside the function. Example: function foo(&$content) { $content = 10; } $var = 20; echo $var; //gets 20 foo($var); echo $var //gets 10 PHP: Without the "&", $var would have remained with a value of 20. As for your first question, close your array first if you haven't already.
Thanks for the explanation about the reference. I still can't get the function working, it's not about the array.
I'd say the code in your function is wrong. The function is getting the value of $content. I checked that without the function code.
$Array is in the global scope. When in a function, you cannot access variables in the global scope unless you pass it to the function in the argument list, or declare the variable as global within the function. Alternatively, you could define the variable inside the function, which will make it accessible to the function, but will make it inaccessible to anything outside that function. Most coding conventions advise against global variables when possible, but whether or not you use them varies greatly on the needs of your app. Sometimes they can't be avoided. Here are a few examples to get your function working: // Method 1, declairing your array inside the function function kaki($content) { $Array = array("All your array data"); // The rest of your function's code here } $content = 'L2C2'; kaki($content); // Method 2, passing your array to the function as an argument function kaki($content, $Array) { // The rest of your function's code here } $Array = array("All your array data"); $content = 'L2C2'; kaki($content, $Array); // Method 3, declairing your array as a global variable function kaki($content) { global $Array; // The rest of your function's code here } $Array = array("All your array data"); $content = 'L2C2'; kaki($content); PHP:
May be your scripting code has some error because of "&" this function. Please re-check it once again and correct it.