Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Zend PHP Certification Study Guide- P5: Hãy thẳng thừng, Giả sử bạn đang thuê một ai đó để giám sát hệ thống và PHP của bạn có nó thu hẹp xuống để hai ứng cử viên. Một trong những ứng cử viên nói, "Oh yeah, tôi biết tất cả về PHP." Các ứng cử viên khác nói, "Oh yeah, tôi biết tất cả về PHP, tôi đã được thông qua kỳ thi chứng chỉ Zend." câu hỏi tiếp theo của bạn có thể sẽ là "Zend Chứng nhận là gì?" Và các ứng viên nói, "Một công ty chuyên về. | 64 Chapter 4 Arrays Note however that if you assign an array element to another variable the assignment will still happen by value because even though the array operator returns a reference to the element the assignment operator will do its job by value a array 1 2 3 b a 1 Will return 2 b 3 echo a 1 Will print 2 c a 1 c test echo a 1 Will print test As you can see here the first assignment does not cause a reference to a 1 to be placed in b. Instead the value of the array element is copied into the variable and when the latter is modified the former remains unchanged. If the assignment takes place by reference however a change to the variable is also reflected in the array element. The array operator can also be used to create an array by assigning a value to a variable as if it were an array array 1 1 var_dump array This will result in array which was empty at the beginning of the script to be initialized as an array with one element whose key is 1 and whose value is 1 array 1 1 int 1 Creating Arrays 65 Finally you can use the array operator to add an element to an array in sequence array 1 var_dump array Assuming that array was never defined it will be reset to an array with one element with a key of 0 and a value of l.The same notes that apply to the addition of an unkeyed element to an array using the array construct also apply to using the array operator without specifying a key. Counting the Number of Elements in an Array The simplest way to count the number of elements in an array is to use the count function array array 10 20 30 echo count array outputs 3 Note that you can t use count to determine whether a variable contains an array because it returns 1 for both an array that contains one element and for any other variable that is not empty or set to Null. Assigning Values from an Array to Multiple Variables The list construct makes it possible to assign the values of an array to multiple individual variables at the same time array array 10 20 30 66 .