andz Posted August 14, 2007 Share Posted August 14, 2007 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'].'<br />'; } } } 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/64813-how-to-modify-and-remove-some-parts-of-an-array/ Share on other sites More sharing options...
PhaZZed Posted August 14, 2007 Share Posted August 14, 2007 Logically what you are going to have to do is this.. array[1] = array[2] array[2] = array[3] array[3] = array[4] Looping through all the elements and shifting them up space up, thus replacing element two in the queue. for ($i==1;$i++;$i<num_elements) { array == array[i+1]; } That kind of idea Link to comment https://forums.phpfreaks.com/topic/64813-how-to-modify-and-remove-some-parts-of-an-array/#findComment-323310 Share on other sites More sharing options...
andz Posted August 14, 2007 Author Share Posted August 14, 2007 I'm not quite good in array. Could you teach me how to delete and modify an array and save it back to database? Link to comment https://forums.phpfreaks.com/topic/64813-how-to-modify-and-remove-some-parts-of-an-array/#findComment-323322 Share on other sites More sharing options...
MadTechie Posted August 14, 2007 Share Posted August 14, 2007 what are you trying to do, exactly? in anycase heres a basic example <?php $theArray = array(0,1,2,3,4,5,6,7,8,9); echo "<pre>"; print_r($theArray); $theArray = RemoveFromArray($theArray, 4); print_r($theArray); function RemoveFromArray($theArray, $item) { if( !is_array($theArray) ) return false; $newArray = array(); foreach($theArray as $K => $V) { if($K != $item) { $newArray[] = $V; } } return $newArray; } ?> returns Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 ) Link to comment https://forums.phpfreaks.com/topic/64813-how-to-modify-and-remove-some-parts-of-an-array/#findComment-323343 Share on other sites More sharing options...
PhaZZed Posted August 14, 2007 Share Posted August 14, 2007 Good solution Mad! Link to comment https://forums.phpfreaks.com/topic/64813-how-to-modify-and-remove-some-parts-of-an-array/#findComment-323352 Share on other sites More sharing options...
MadTechie Posted August 14, 2007 Share Posted August 14, 2007 thanks:) i forgot to say change $newArray[] = $V; to $newArray[$K] = $V; if you wish to keep the arraykeys Link to comment https://forums.phpfreaks.com/topic/64813-how-to-modify-and-remove-some-parts-of-an-array/#findComment-323355 Share on other sites More sharing options...
andz Posted August 15, 2007 Author Share Posted August 15, 2007 Sorry for the late reply... I'll give it a try... Link to comment https://forums.phpfreaks.com/topic/64813-how-to-modify-and-remove-some-parts-of-an-array/#findComment-324443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.