PHP函数

在数组第一个插入元素:

$goods_class = [
	'0' => [
		'class_id' => '1',
		'class_name' => '鱼'
	],
	'1' => [
		'class_id' => '2',
		'class_name' => '虾'
	],
];
$arr = [
	'class_id' => '0',
	'class_name' => '全部商品'
];
array_unshift($goods_class, $arr);
print_r($goods_class);

打印结果:
[
	'0' => [
		'class_id' => '0',
		'class_name' => '全部商品'
	],
	'1' => [
		'class_id' => '1',
		'class_name' => '鱼'
	],
	'2' => [
		'class_id' => '2',
		'class_name' => '虾'
	],
]

你可能感兴趣的:(代码笔记,php函数)