Home  >  Article  >  Backend Development  >  PHP interview written test questions 1_PHP tutorial

PHP interview written test questions 1_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:13:25821browse

This article shares an article about PHP interview written test question 1. Friends in need can refer to it

* Please implement a function, enter a piece of text, parse the text into an array, and pass the key of each row of the array element Input parameters are specified.

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

For example, enter:

$columnNames = array('Fruit', 'Number', 'Color');
The code is as follows
 代码如下 复制代码

$text = "
Apple,20,red
Pear,10,yellow
";
$columnNames = array('Fruit', 'Number', 'Color')

函数返回:
array(
array('Fruit'=>'Apple', 'Number'=>'20', 'Color'=>'red'),
array('Fruit'=>'Pear', 'Number'=>'10', 'Color'=>'yellow'),
)
*/

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;
 
}
$text = "

Apple,20,red

Pear,10,yellow

";

$columnNames = array('Fruit', 'Number', 'Color')

Function returns:

array(

array('Fruit'=>'Apple', 'Number'=>'20', 'Color'=>'red'),

array('Fruit'=>'Pear', 'Number'=>'10', 'Color'=>'yellow'),

)

*/

Instance methods

Question 2

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

1. Users can correctly obtain the above types of gold coins

2. Users can know how many gold coins they have available for consumption and how many gold coins are frozen at any time 3. The frozen gold coins will become consumable gold coins after the freezing period


4. Users can spend their own available gold coins

You only need to design a feasible solution, describing the database structure and logical algorithm:

1. Distribute gold coins A and gold coins B

2. Get how many gold coins are currently available, consume available gold coins, obtain the freezing status of currently frozen gold coins, convert frozen gold coins to usable gold coins, and recover frozen gold coins







Category:
Interview questions


$arr =array();

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

$file and $arr = explode("rn", $file);
$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.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629183.htmlTechArticleThis article shares an article about PHP interview written test question 1. Friends in need can refer to it* Please implement a function , input a piece of text, parse the text into an array, each line of the array...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn