Học php, mysql và javascript - p 7

Figure 3-4. A multidimensional array simulated with matchboxes three more arrays, as in Example 3-5, in which the array is set up with a game already in progress. Example 3-5. Defining a two-dimensional array Once again, we’ve moved up a step in complexity, but it’s easy to understand if you grasp the basic array syntax. There are three array() constructs nested inside the outer array() construct. To then return the third element in the second row of this array, you would use the following PHP command, which will display an “x”: echo $oxo[1][2]; Remember that array indexes (pointers at elements within an array) start from. | Figure 3-4. A multidimensional array simulated with matchboxes three more arrays as in Example 3-5 in which the array is set up with a game already in progress. Example 3-5. Defining a two-dimensional array php oxo array array x o array o o x array x o Once again we ve moved up a step in complexity but it s easy to understand if you grasp the basic array syntax. There are three array constructs nested inside the outer array construct. To then return the third element in the second row of this array you would use the following PHP command which will display an x echo oxo 1 2 Remember that array indexes pointers at elements within an array start from zero not one so the 1 in the previous command refers to the second of the three arrays and the 2 references the third position within that array. It will return the contents of the matchbox three along and two down. As mentioned arrays with even more dimensions are supported by simply creating more arrays within arrays. However we will not be covering arrays of more than two dimensions in this book. The Structure of PHP 41 And don t worry if you re still having difficulty getting to grips with using arrays as the subject is explained in detail in Chapter 6. Variable naming rules When creating PHP variables you must follow these four rules Variable names must start with a letter of the alphabet or the _ underscore character. Variable names can contain only the characters a-z A-Z 0-9 and _ underscore . Variable names may not contain spaces. If a variable must comprise more than one word it should be separated with the _ underscore character. . user_name . Variable names are case-sensitive. The variable High_Score is not the same as the variable high_score. Operators Operators are the mathematical string comparison and logical commands such as plus minus times and divide. PHP looks a lot like plain arithmetic for instance the following statement outputs 8 echo 6 2 Before moving on to learn what PHP can do for you take a

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.