Php interview question 1

Source: Internet
Author: User
Tags explode function prototype instance method pear

* 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: Copy code

$ 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: Copy code
$ 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;
 
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.