otuatail Posted November 17, 2007 Share Posted November 17, 2007 Can anyone tell me how to add extra strings to an exsisting array $data = array("AAA","BBB","CCC"); $data . "DDD"; // dosn't work. Desmond. Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/ Share on other sites More sharing options...
thebadbad Posted November 17, 2007 Share Posted November 17, 2007 Simple: <?php $data = array("AAA", "BBB", "CCC"); array_push($data, "DDD"); ?> Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/#findComment-393351 Share on other sites More sharing options...
rajivgonsalves Posted November 17, 2007 Share Posted November 17, 2007 Simple: <?php $data = array("AAA", "BBB", "CCC"); array_push($data, "DDD"); ?> also you can do $data[] = "DDD"; Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/#findComment-393355 Share on other sites More sharing options...
thebadbad Posted November 17, 2007 Share Posted November 17, 2007 Hehe, even simpler But you can't add multiple strings that way, right? Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/#findComment-393357 Share on other sites More sharing options...
rajivgonsalves Posted November 17, 2007 Share Posted November 17, 2007 Yep thats why I quoted your post just giving options Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/#findComment-393358 Share on other sites More sharing options...
otuatail Posted November 17, 2007 Author Share Posted November 17, 2007 Thanks for that. (Hehe, even simpler But you can't add multiple strings that way, right?) wasn't my reply though. Both examples work fine thanks. One thing is there a function to search an aray for a value or do i have to iterate through the entire string. Can't find a usefull function. Desmond. Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/#findComment-393362 Share on other sites More sharing options...
rajivgonsalves Posted November 17, 2007 Share Posted November 17, 2007 you can use array_search function more information at http://php.net/array_search Link to comment https://forums.phpfreaks.com/topic/77704-solved-add-to-string-array/#findComment-393364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.