PHP 5/MySQL Programming- P36

PHP 5/MySQL Programming- P36:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 153 result distance cityA cityB print h3 The distance between cityA and cityB is result miles. h3 body html Building the Two-Dimensional Associative Array The basic approach to building a two-dimensional array is the same whether it s a normal array or uses associative indexing. Essentially you create each row as an array and then build an array of the existing arrays. In the traditional array the indices were automatically created. The development of an associative array is a little more complex because you need to specify the key for each value. As an example look at the code used to generate the indy array indy array Indianapolis 0 New York 648 Tokyo 6476 London 4000 Inside the array I used city names as indices. The value for each index refers to the distance from the current city Indianapolis to the particular destination. The distance from Indianapolis to Indianapolis is 0 and the distance from Indy to New York is 648 and so on. I created an associative array for each city and put those associative arrays together in a kind of mega-associative array set up master array distance array Indianapolis indy New York ny Tokyo tokyo London london Chapter 5 Better Arrays and String Handling This new array is also an associative array but each of its indices refers to an array of distances. b Cl c c 5 ci a ci j V A Cl Getting Data from the Two-Dimensional Associative Array Once the two-dimensional array is constructed it s extremely easy to use. The city names themselves are used as indices so there s no need for a separate array to hold city names. The data can be output in two lines of code result distance cityA cityB print h3 The distance between cityA and cityB is result miles. h3 a c S S C b a o b a You can combine associative and normal arrays. It is possible to have a list of associative arrays and put them together in a normal array or vice versa. PHP s array-handling capabilities allow for a phenomenal level of control over your data structures. 0 A S u a x a

Không thể tạo bản xem trước, hãy bấm tải xuống
120    344    13    21-03-2023
Đã 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.