anatak Posted January 27, 2014 Share Posted January 27, 2014 Can someone point me to a good tutorial that explains the basic syntax of arrays ? ASI know how to use foreach($array AS $var){ } but I don't really know what the syntax is supposed to mean. =>what does the => mean in ($array AS $var => $value){}? I keep running into basic problems with arrays and I am trying to understand how to manipulate arrays. the problem is that I can get things more or less working without really understanding what I am doing. thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/285699-basic-array-syntax-as-and/ Share on other sites More sharing options...
kicken Posted January 27, 2014 Share Posted January 27, 2014 I know how to use foreach($array AS $var){ } but I don't really know what the syntax is supposed to mean. 'as' generally indicates that you are aliasing something. In the context of foreach it indicates that the items in the array will be assigned to the given variables within the loop body. Basically what that structure says in english is: For each item in $array, assign the item's value to $var and execute the instructions below. what does the => mean in ($array AS $var => $value){}? => indicates a key and value pair. On the left side of => is the key, and on the right is the value. So what that line is saying in english would be: For each item in $array, assign the item's key (aka index) to $var and the item's value to $value and execute the instructions below. => may also be used when creating an array, such as $array = array( 'key' => 'value' //, 'more' => 'pairs...' ); Quote Link to comment https://forums.phpfreaks.com/topic/285699-basic-array-syntax-as-and/#findComment-1466674 Share on other sites More sharing options...
cyberRobot Posted January 27, 2014 Share Posted January 27, 2014 More information about arrays and the foreach loop (including examples) can be found here: http://www.php.net/manual/en/control-structures.foreach.php Quote Link to comment https://forums.phpfreaks.com/topic/285699-basic-array-syntax-as-and/#findComment-1466728 Share on other sites More sharing options...
anatak Posted January 28, 2014 Author Share Posted January 28, 2014 thank you very much. Comprehension is slowly dawning. Quote Link to comment https://forums.phpfreaks.com/topic/285699-basic-array-syntax-as-and/#findComment-1466819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.