note 111898 deleted from function.array-push by googleguy
| From: | googleguy@php.net | Date: | Tue, 09 Apr 2013 17:49:45 +0000 |
| Subject: | note 111898 deleted from function.array-push by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194415@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"
}
*/