Home > Backend Development > PHP Tutorial > sql查询出来后转乘数组,我应该怎么把数组里的值存入到变量

sql查询出来后转乘数组,我应该怎么把数组里的值存入到变量

WBOY
Release: 2016-06-23 13:36:22
Original
1170 people have browsed it

?Array ( [0] => Array ( [myname] => 魏亮 ) [1] => Array ( [myname] => 宋向东 ) [2] => Array ( [myname] => 王克娇 ) [3] => Array ( [myname] => 刘彦宾 ) [4] => Array ( [myname] => 程秀芹 ) [5] => Array ( [myname] => 李国振 ) )
Copy after login

这是查出来的数据
$sql = "select myname from xs_staff";$js = get_array($sql);print_r($js);
Copy after login

	function get_array($sql){	    $result = mysql_query($sql);	    $arr = array();	    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){	        $arr[] = $row;	    }	    mysql_free_result($result);	    mysql_close($conn);	    return $arr;	}
Copy after login


求赋值方法。。我用list()   也不行。  $a = print_r($js[0]);这样也不行。。。


回复讨论(解决方案)

你那是二维数组

echo $js[0]['name']; 

就可以了。注意第一维的下标从 0 到 count($js) - 1

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template