PHP Interview pen question one _php tutorial

Source: Internet
Author: User
This article shares an article about the PHP interview pen question one, the need for friends can refer to

* Please implement a function, enter a text, parse the text into an array, the key of each line element of the array is specified by the input parameter.

Functional Prototypes: 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 returns:
Array
Array (' Fruit ' = ' Apple ', ' number ' = ' + ', ' Color ' = ' red '),
Array (' Fruit ' = ' = ' Pear ', ' number ' = ' ', ' ' "'" ' "') ', ' 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 Two

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

1, the user can obtain the above types of gold coins correctly

2, users can always know how many coins they can spend, how many coins are frozen

3. The frozen gold coins can be consumed after the freezing period.

4, the user can consume their own available gold coins

You only need to design a workable scenario that describes the database structure and logical algorithms:

1. Issue a gold coin and issue B gold coins

2, to obtain the current number of available gold coins, consumption of available gold coins, to obtain the current frozen coins frozen, frozen gold coins to usable gold, recycling frozen gold coins

Category: Face 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;

}

http://www.bkjia.com/PHPjc/629183.html www.bkjia.com true http://www.bkjia.com/PHPjc/629183.html techarticle This article shares an article about the PHP interview pen question one, the need for friends can refer to * Please implement a function, enter a text, the text into an array, the array of each line ...

  • 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.