如何在php中将数组划分为两个索引

问题描述:

i am fetching time from mysql_db below is my code...

$sql="SELECT * from employee_timings where emp_timing_date='$date'";
$query=mysql_query($sql);
$array=array();
while ($result=mysql_fetch_array($query)) {
    # code...
    $emp_starting_time=$result['emp_in_time'];

}

below is my table from which i am fetching the values...enter image description here the issue is it gives me result in following format 11:00:0014:00:00 and when i echo this

 echo $emp_starting_time[0];

it outputs the first character of first time i.e 1 and second time i.e 1 what i want is that whenever i echo

    $emp_Starting_time[0]

it should display the whole 1st starting_time which is 11:00:00 kindly tell me how to achieve that

我从下面的mysql_db中获取时间是我的代码...... p>

   $ sql =“SELECT * from employee_timings where emp_timing_date ='$ date'”; 
 $ query = mysql_query($ sql); 
 $ array = array(); 
while($ result = mysql_fetch_array($ query)  )){
#code ... 
 $ emp_starting_time = $ result ['emp_in_time']; 
 
} 
  code>  pre> 
 
 

下面是我的表格 我正在获取价值...... 问题是它给出了以下格式的结果:11:00:0014:00:00 当我回应这个 p >

  echo $ emp_starting_time [0]; 
  code>  pre> 
 
 

它输出第一次的第一个字符,即1和第二次,即1 我想要的是每当我回显 p>

  $ emp_Starting_time [0] 
  code>  pre> 
 
 

它应该显示整个 第一个起始时间是11:00:00 告诉我 如何实现 p> div>

You give $emp_starting_time variable the value $result['emp_in_time'];. It contains the result you are looking for in a string format. When you write echo $emp_starting_time[0];, it returns you the fist charracter of this string. Try echo $emp_starting_time;

UPDATE

You can create an array outside of the loop and then push in it each value:

$array=array();
while ($result=mysql_fetch_array($query)) {
    # code...
    array_push($array, $result['emp_in_time']);
}