Php interview question 1 _ PHP Tutorial

Source: Internet
Author: User
Php interview question 1. This article shares a php interview question 1. if you need it, refer to * Implement a function, input a piece of text, and parse the text into an array, array each line this article shares an article about php interview question 1. if you need it, please refer to it.

* Implement a function. input a piece of text and parse the text into an array. the key of each element in the array line is specified by the input parameter.

Function prototype: function ExplodeLines ($ text, $ columnNames)

For example, enter:

The code is as follows:

$ Text ="
Apple, 20, red
Pear, 10, yellow
";
$ ColumnNames = array ('fruit', 'number', 'color ')

Function return:
Array (
Array ('fruit' => 'apple', 'number' => '20', 'color' => 'red '),
Array ('fruit' => 'pear ', 'number' => '10', 'color' => 'yellow '),
)
*/

Instance method

The code is as follows:
$ Arr = array ();

$ File = file_get_contents ("file.txt ");

$ File and $ arr = explode ("rn", $ file );

$ ColumnNames = array ('fruit', 'number', 'color ');

$ Rs = ExplodeLines ($ arr, $ columnNames );

// Print_r ($ rs );

Function ExplodeLines ($ text, $ columnNames ){
$ Array = array ();
Foreach ($ text as $ key => $ val ){
If ($ val! = ""){
$ Array [] = array_combine ($ columnNames, explode (",", $ val ));
}
}
Return $ array;

}

Question 2

Design a system (database structure and logical process) to meet the following requirements:

1. the user can correctly obtain the above-mentioned gold coins

2. Users can know at any time how much gold coins they have can be consumed and how much gold coins are frozen.

3. Frozen Gold coins can be consumed after the freeze period

4. Users can purchase their own available gold coins.

You only need to design a feasible solution to describe the database structure and logic algorithm:

1. issue A gold coin and B gold coin

2. obtain the currently available gold coins, consume available gold coins, obtain frozen gold coins, convert frozen gold coins to available gold coins, and recycle frozen gold coins.

Category: interview questions


$ Arr = array ();

$ File = file_get_contents ("file.txt ");

$ File and $ arr = explode ("rn", $ file );

$ ColumnNames = array ('fruit', 'number', 'color ');

$ Rs = ExplodeLines ($ arr, $ columnNames );

// Print_r ($ rs );

Function ExplodeLines ($ text, $ columnNames ){
$ Array = array ();
Foreach ($ text as $ key => $ val ){
If ($ val! = ""){
$ Array [] = array_combine ($ columnNames, explode (",", $ val ));
}
}
Return $ array;

}

Implement a function, input a piece of text, and parse the text into an array, each row of the array...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.