andz Posted August 16, 2007 Share Posted August 16, 2007 Although the first posts regarding array modification to this site solved my problem, though I still want to have other solutions as options. This php query below fetch only the array from the table. <?php foreach (query_to_retrieve_the_array_from_table_by_email($email) as $res) { $separator = "~"; $content = $res['catid']; $splitContent = explode($separator, $content); foreach ($splitContent as $cont) { $extractContent = $cont; if (!empty($extractContent)) { $result = mysql_query("SELECT catid, name FROM categories_table WHERE catid IN (".$extractContent.")"); while ($row = mysql_fetch_assoc($result)) { $finalContent[] = $row['catid']. ' '.$row['name'].' '; } } } echo implode(' ', $finalContent); } ?> It's working. Could you teach me how to modify and delete an array(), usually not all of the contents of an array should be deleted. Example: array_content = 1~2~3~4~5, what will be the query if I want to remove the 2 from the array_content??? And how could I modify an array??? I don't know which part I'm going to start and what is/ the query(ies) that I'm going to use. I'm not quite good in array, I only know how to fetch and extract array from a table. Link to comment https://forums.phpfreaks.com/topic/65185-other-solutions-on-how-to-modify-and-remove-some-parts-of-an-array/ Share on other sites More sharing options...
btherl Posted August 16, 2007 Share Posted August 16, 2007 I typically use a loop like this: $array = array(1, 2, 3, 4, 5); # Array after explode(), if you start with '1~2~3~4~5' foreach ($array as $key => $value) { if ($value == 2) unset($array[$key]); } var_dump($array); This will delete the "2" from the array. Note that it won't update the array indices, so be careful if you rely on these. Link to comment https://forums.phpfreaks.com/topic/65185-other-solutions-on-how-to-modify-and-remove-some-parts-of-an-array/#findComment-325473 Share on other sites More sharing options...
andz Posted August 16, 2007 Author Share Posted August 16, 2007 Its quite simple. I'm just having a little hard time when it comes to array, though I knew how to use them in some application. Thanks for your post. Godspeed Link to comment https://forums.phpfreaks.com/topic/65185-other-solutions-on-how-to-modify-and-remove-some-parts-of-an-array/#findComment-325474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.