note 109307 deleted from function.array-slice by danbrown
| From: | danbrown@php.net | Date: | Mon, 16 Jul 2012 15:50:21 +0000 |
| Subject: | note 109307 deleted from function.array-slice by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189229@lists.php.net to get a copy of this message | ||
Note Submitter: dayanneramosweb at gmail dot com
----
function array_push_in_position($arrayAInserir,$indiceInserir,$insercao){
$parte1 = array_slice($arrayAInserir,0,$indiceInserir);
$parte2 = array_slice($arrayAInserir,$indiceInserir);
array_push($parte1,$insercao);
return array_merge($parte1,$parte2);
}
//ex: quero inserir a palavra house, apos apos a melon.
$words = array('banana','melon','car');
$words = array_push_in_position($words ,2,'house');
/* result:
array(4) {
[0]=>
string(6) "banana"
[1]=>
string(5) "melon"
[2]=>
string(5) "house"
[3]=>
string(3) "car"
}
*/