PHP 5/MySQL Programming- P32

PHP 5/MySQL Programming- P32: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 | C H A P T E RJ Better Arrays and String Handling In this chapter you learn some important skills that improve your work with data. You learn about some more-sophisticated ways to work with arrays and how to manage text information with more flair. Specifically you learn how to do these things Manage arrays with the foreach loop Create and use associative arrays Extract useful information from some of PHP s built-in arrays Build basic two-dimensional arrays Build two-dimensional associative arrays Break a string into smaller segments Search for one string inside another 134 PHP 5 MySQL Programming for the Absolute Beginner Introducing the Word Search Program Creator By the end of this chapter you can create a fun program that generates word search puzzles. The user enters a series of words into a list box as shown in Figure . FIGURE The user enters a list of words and a size for the finished puzzle. The program then tries to generate a word search based on the user s word list. It isn t always possible but the program can usually generate a puzzle. One possible solution for the word list shown in Figure 5. 1 is demonstrated in Figure . If desired the program can also generate an answer key based on the puzzle. This capability is shown in Figure . The secret to the word find game and indeed most computer programs is the way the data is handled. Once I determined a good scheme for working with the data in the program the actual programming wasn t too tough. 135 figure This puzzle contains all the words in the list. Chapter 5 Better Arrays and String Handling figure Here s the answer key for the puzzle. Using the foreach Loop to Work ith an Array As I mention in chapter 4 Loops and Arrays for loops and arrays are natural companions. In fact PHP supplies a special kind of loop called the foreach loop that makes it even easier to step through each array .

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
34    85    1    26-04-2024
Đã 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.