Hàm Array ( [0] => html [1] => css [2] => php [3] => js )4 sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm. sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.freetuts.net, không được copy dưới mọi hình thức.
Cú pháp
Cú pháp: Array ( [0] => html [1] => css [2] => php [3] => js )5: Array ( [0] => html [1] => css [2] => php [3] => js )5
Trong đó::
- Array ( [0] => html [1] => css [2] => php [3] => js )6 là mảng dữ liệu ban đầu.
- Array ( [0] => html [1] => css [2] => php [3] => js )7 là các phần tử được thêm vào. là các phần tử được thêm vào.
Ví dụ
Code
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";Kết quả
Array ( [0] => html [1] => css [2] => php [3] => js )Hai phần tử Array ( [0] => html [1] => css [2] => php [3] => js )8 và Array ( [0] => html [1] => css [2] => php [3] => js )9 đã được thêm vào đầu mảng Array ( [0] => html [1] => css [2] => php [3] => js )6.
Bài viết này được đăng tại [free tuts .net]
Tham khảo: php.net
robert dot wills at fuzzbrain dot uklinux dot net ¶ sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.
20 years ago
- sahn at hmc dot edu ¶
- 21 years ago
- chris dot NoThxSpam dot given at hp dot com ¶
- sahn at hmc dot edu ¶
- 21 years ago
- chris dot NoThxSpam dot given at hp dot com ¶
- sahn at hmc dot edu ¶
- 21 years ago
- chris dot NoThxSpam dot given at hp dot com ¶
- 19 years ago
- John Brooking ¶
16 years agofreetuts.net, không được copy dưới mọi hình thức.
lagroue ¶
Hàm Array ( [0] => html [1] => css [2] => php [3] => js )4 sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.: Array ( [0] => html [1] => css [2] => php [3] => js )5
Nội dung chính:
- Định nghĩa hàm array_unshift() trong PHP
- Cú pháp của hàm array_unshift() trong PHP là: là các phần tử được thêm vào.
Ví dụ minh họa cách sử dụng hàm array_unshift() trong PHP:
Description
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";Return Values
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.Cú pháp
Cú pháp: Array ( [0] => html [1] => css [2] => php [3] => js )5
Trong đó:
sahn at hmc dot edu ¶
21 years ago
21 years ago
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";9
chris dot NoThxSpam dot given at hp dot com ¶
- 19 years ago
- John Brooking ¶
- 16 years ago
- lagroue ¶
chris dot NoThxSpam dot given at hp dot com ¶
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?>19 years ago
John Brooking ¶
robert dot wills at fuzzbrain dot uklinux dot net ¶ sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.
20 years ago
- sahn at hmc dot edu ¶
- 21 years ago
- chris dot NoThxSpam dot given at hp dot com ¶
- sahn at hmc dot edu ¶
- 21 years ago
- chris dot NoThxSpam dot given at hp dot com ¶
- 19 years ago
- John Brooking ¶
16 years agofreetuts.net, không được copy dưới mọi hình thức.
lagroue ¶
Hàm Array ( [0] => html [1] => css [2] => php [3] => js )4 sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.: Array ( [0] => html [1] => css [2] => php [3] => js )5
Nội dung chính:
- Định nghĩa hàm array_unshift() trong PHP
- Cú pháp của hàm array_unshift() trong PHP là: là các phần tử được thêm vào.
Ví dụ minh họa cách sử dụng hàm array_unshift() trong PHP:
Description
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";Return Values
Array ( [0] => html [1] => css [2] => php [3] => js )Cú pháp
Cú pháp: Array ( [0] => html [1] => css [2] => php [3] => js )5
Trong đó:
sahn at hmc dot edu ¶
21 years ago
21 years ago
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";9
chris dot NoThxSpam dot given at hp dot com ¶
- 19 years ago
- John Brooking ¶
- 16 years ago
- lagroue ¶
chris dot NoThxSpam dot given at hp dot com ¶
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?>19 years ago
John Brooking ¶
robert dot wills at fuzzbrain dot uklinux dot net ¶ sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.
20 years ago
- sahn at hmc dot edu ¶
- 21 years ago
- chris dot NoThxSpam dot given at hp dot com ¶
- 19 years ago
- John Brooking ¶
16 years agofreetuts.net, không được copy dưới mọi hình thức.
lagroue ¶
Hàm Array ( [0] => html [1] => css [2] => php [3] => js )4 sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.: Array ( [0] => html [1] => css [2] => php [3] => js )5
Nội dung chính:
- Định nghĩa hàm array_unshift() trong PHP
- Cú pháp của hàm array_unshift() trong PHP là: là các phần tử được thêm vào.
Ví dụ minh họa cách sử dụng hàm array_unshift() trong PHP:
Description
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";Return Values
Array ( [0] => html [1] => css [2] => php [3] => js )Cú pháp
Cú pháp: Array ( [0] => html [1] => css [2] => php [3] => js )5
Trong đó:
sahn at hmc dot edu ¶
21 years ago
Cú pháp của hàm array_unshift() trong PHP là:
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";9
Tham số
- array: Bắt buộc. Xác định một mảng
- value1: Bắt buộc. Xác định một value để chèn
- value2: Tùy ý. Xác định một value để chèn
- value3: Tùy ý. Xác định một value để chèn
Ví dụ minh họa cách sử dụng hàm array_unshift() trong PHP:
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?>Lưu chương trình trên trong một file có tên là test.php trong htdocs, sau đó mở trình duyệt và gõ địa chỉ //localhost:8080/test.php sẽ cho kết quả:
Xem thêm Hàm trong php
Hàm Array ( [0] => html [1] => css [2] => php [3] => js )4 sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm. sẽ thêm một hoặc nhiều phần tử vào đầu mảng.Hàm trả về số nguyên là số phần tử của mảng mới được thêm.
Cú pháp
Cú pháp: Array ( [0] => html [1] => css [2] => php [3] => js )5: Array ( [0] => html [1] => css [2] => php [3] => js )5
Trong đó::
- Array ( [0] => html [1] => css [2] => php [3] => js )6 là mảng dữ liệu ban đầu.
- Array ( [0] => html [1] => css [2] => php [3] => js )7 là các phần tử được thêm vào. là các phần tử được thêm vào.
Ví dụ
Code
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";Kết quả
Array ( [0] => html [1] => css [2] => php [3] => js )Hai phần tử Array ( [0] => html [1] => css [2] => php [3] => js )8 và Array ( [0] => html [1] => css [2] => php [3] => js )9 đã được thêm vào đầu mảng Array ( [0] => html [1] => css [2] => php [3] => js )6.
Tham khảo: php.net
(PHP 4, PHP 5, PHP 7, PHP 8)
array_unshift — Prepend one or more elements to the beginning of an array — Prepend one or more elements to the beginning of an array
Description
array_unshift(array $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";5, mixed $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";6): int(array $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";5, mixed $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";6): int
Note: :
Resets array's internal pointer to the first element.
Parameters
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";7The input array.
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";8The values to prepend.
Return Values
Returns the new number of elements in the $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";7.
Changelog
7.3.0 | array_unshift(array $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";5, mixed $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";6): int |
Note:
Resets array's internal pointer to the first element. array_unshift() example
Array ( [0] => html [1] => css [2] => php [3] => js )0
Parameters
Array ( [0] => html [1] => css [2] => php [3] => js )3$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";7
- The input array.
- $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";8
- The values to prepend.
Return Values ¶
Returns the new number of elements in the $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";7.
Array ( [0] => html [1] => css [2] => php [3] => js )1
Array ( [0] => html [1] => css [2] => php [3] => js )2
Array ( [0] => html [1] => css [2] => php [3] => js )3
Array ( [0] => html [1] => css [2] => php [3] => js )4Changelog ¶
Version
Array ( [0] => html [1] => css [2] => php [3] => js )5
Array ( [0] => html [1] => css [2] => php [3] => js )6
Array ( [0] => html [1] => css [2] => php [3] => js )4This function can now be called with only one parameter. Formerly, at least two parameters have been required. ¶
Examples
Array ( [0] => html [1] => css [2] => php [3] => js )8
Array ( [0] => html [1] => css [2] => php [3] => js )9
Array ( [0] => html [1] => css [2] => php [3] => js )4Example #1 array_unshift() example ¶
The above example will output:
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 1
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 2
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 3
Array ( [0] => html [1] => css [2] => php [3] => js )4See Also ¶
array_shift() - Shift an element off the beginning of array
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 5
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 6
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 7
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 8array_push() - Push one or more elements onto the end of array ¶
array_pop() - Pop the element off the end of array
<?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> 9
sergei at gmx dot net ¶ ¶
14 years ago
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";0
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";1
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";2
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";3Anonymous ¶ ¶
10 years ago
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";4
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";5
Array ( [0] => html [1] => css [2] => php [3] => js )4daniel at smallboxcms dot com ¶ ¶
7 years ago
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";7
$array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";8
Array ( [0] => html [1] => css [2] => php [3] => js )4Richard Akindele ¶ ¶
6 years ago
Array ( [0] => html [1] => css [2] => php [3] => js )0
Array ( [0] => html [1] => css [2] => php [3] => js )1
Array ( [0] => html [1] => css [2] => php [3] => js )4amschroeder at gmail dot com ¶ ¶
array_pop() - Pop the element off the end of array
Array ( [0] => html [1] => css [2] => php [3] => js )3
Array ( [0] => html [1] => css [2] => php [3] => js )4
Array ( [0] => html [1] => css [2] => php [3] => js )4