shadd Posted June 24 Share Posted June 24 array(1) { ["data"]=> array(2) { [0]=> array(14) { ["Q_id"]=> string(438) "1.1.1|||1.1.2|||1.1.3|||1.1.4|||1.1.5|||1.1.6|||1.1.7|||1.1.8|||1.1.9|||1.1.10|||1.1.11|||1.1.12|||1.1.13|||1.1.14|||1.1.15|||1.1.16|||1.1.17|||1.1.18|||1.1.19|||1.1.20|||1.1.21|||1.1.22|||1.1.23|||1.1.24|||1.1.25|||1.1.26|||1.1.27|||1.1.28|||1.1.29|||1.1.30|||1.1.31|||1.1.32|||1.1.33|||1.1.34|||1.1.35|||1.1.36|||1.1.37|||1.1.38|||1.1.39|||1.1.40|||1.1.41|||1.1.42|||1.1.43|||1.1.44|||1.1.45|||1.1.46|||1.1.47|||1.1.48|||1.1.49|||1.1.50" ["QueNo"]=> NULL ["qNo"]=> string(238) "1|||2|||3|||4|||5|||6|||7|||8|||9|||10|||11|||12|||13|||14|||15|||16|||17|||18|||19|||20|||21|||22|||23|||24|||25|||26|||27|||28|||29|||30|||31|||32|||33|||34|||35|||36|||37|||38|||39|||40|||41|||42|||43|||44|||45|||46|||47|||48|||49|||50"["SECTION"]=> string(9) "SECTION A" } [1]=> array(14) { ["Q_id"]=> string(106) "1.1.51|||1.1.51.2|||1.1.51.3|||1.1.51.4|||1.1.51.5|||1.1.51.6|||1.1.51.7|||1.1.51.8|||1.1.51.9|||1.1.51.10" ["QueNo"]=> string(33) "b|||c|||d|||e|||f|||g|||h|||i|||j" ["qNo"]=> string(47) "51|||51|||51|||51|||51|||51|||51|||51|||51|||51"["SECTION"]=> string(9) "SECTION B" } } } from the above array, i need to associate values in each key to others for display. i have tried getting different field to separate array like so: for ($i = 0; $i < count($data); $i++){ $Section=$data[$i]['SECTION']); $Q_Id=explode('|||',$data[$i]['Q_id']); $QueNo=explode('|||',$data[$i]['qNo']);} First the data is overwritten in the arrays($Q_Id,$QueNo) how can i avoid that. So that on second loop data is simply added to the end of the array after exlode() Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/ Share on other sites More sharing options...
mac_gyver Posted June 24 Share Posted June 24 https://www.php.net/manual/en/function.array-merge.php Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628650 Share on other sites More sharing options...
shadd Posted June 24 Author Share Posted June 24 1 hour ago, mac_gyver said: https://www.php.net/manual/en/function.array-merge.php Could you please show me in code,because after the first itertion ,the next iteration overwrites the first, so how will array_merge() get a second argument then?? Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628656 Share on other sites More sharing options...
Barand Posted June 24 Share Posted June 24 As an aside - if the array you posted isn't in the structure you need, why did you create it like that in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628657 Share on other sites More sharing options...
shadd Posted June 24 Author Share Posted June 24 Well it was the first thought on how to get the data together as a first working solution. But now as you go along in the display, things come up and iam forced to look of another hack around . can you assist please? Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628658 Share on other sites More sharing options...
Solution Barand Posted June 24 Solution Share Posted June 24 9 minutes ago, shadd said: can you assist please? Not without any psychic abilities. Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628659 Share on other sites More sharing options...
Barand Posted June 24 Share Posted June 24 13 minutes ago, Barand said: Not without any psychic abilities. In other words I have no idea what the original source of your data looks like, and I have no idea what you want the final display to look like. Any processing to go from (1) to (2) is completely dependent on knowing those. All you have given us so far is an intermediate array that isn't what you want. Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628661 Share on other sites More sharing options...
shadd Posted June 24 Author Share Posted June 24 I figured it out as i was seeking assistance. In the for loop is where i had to do the data display and not outside of it.That way the array is still present during the iteration. All your replies were a help thanks Quote Link to comment https://forums.phpfreaks.com/topic/321922-how-to-append-data-to-end-of-array-in-php/#findComment-1628664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.