Re: [PHP] Array unset()
Ken Robinson kenrb...@rbnsn.com wrote: At 08:50 PM 9/23/2012, Ron Piggott wrote: I am wondering if there is a way to remove from an array where the value is 0 (âzeroâ) Array example: $total_points_awarded = array( 1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 ); In this example I would like to remove element # 4 and # 6. The âkeyâ ( 1,3,4,5,6 ) represents the memberâs account #. It is an auto_increment value in a mySQL table The âvalueâ ( 17,14,0,1,0 ) represents their score. The application for this is a list of the top users. If someone has 0 points I donât want to include them. Any thoughts? Any help is appreciated. Look at array_filter() ... http://php.net/array_filter ?php $total_points_awarded = array( 1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 ); print_r(array_filter($total_points_awarded)); Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Wouldn't it be far easier to do this at the database level in the query? -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array unset()
I am wondering if there is a way to remove from an array where the value is 0 (“zero”) Array example: $total_points_awarded = array( 1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 ); In this example I would like to remove element # 4 and # 6. The “key” ( 1,3,4,5,6 ) represents the member’s account #. It is an auto_increment value in a mySQL table The “value” ( 17,14,0,1,0 ) represents their score. The application for this is a list of the top users. If someone has 0 points I don’t want to include them. Any thoughts? Any help is appreciated. Ron Ron Piggott www.TheVerseOfTheDay.info
Re: [PHP] Array unset()
At 08:50 PM 9/23/2012, Ron Piggott wrote: I am wondering if there is a way to remove from an array where the value is 0 (âzeroâ) Array example: $total_points_awarded = array( 1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 ); In this example I would like to remove element # 4 and # 6. The âkeyâ ( 1,3,4,5,6 ) represents the memberâs account #. It is an auto_increment value in a mySQL table The âvalueâ ( 17,14,0,1,0 ) represents their score. The application for this is a list of the top users. If someone has 0 points I donât want to include them. Any thoughts? Any help is appreciated. Look at array_filter() ... http://php.net/array_filter ?php $total_points_awarded = array( 1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 ); print_r(array_filter($total_points_awarded)); Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array unset
Hi, I my system can handle invisible modules, so they can't show in the menu but stills works... here is the code: $c = count($modules)-1; for($i = 0; $i = $c; $i++) { if($modules[$i]['moduleVisibility'] == 0) { unset($modules[$i]); } } $m = 0; $c = count($modules)-1; for($i = 0; $i = $c ; $i++) { if($modules[$i]['modulePath'] == $framework-modules-module['modulePath']) { $output .= 'td class=menuitem_active onmouseover=menuHover(\'mainmenu\', '.$m.', \'menuitem_active\') onmouseout=menuHover(\'mainmenu\', '.$m.', \'menuitem_active\') a href='.$framework-output- get_config_vars('Address').$modules[$i]['moduleController'].'/ '.$modules[$i]['modulePath'].''; } else { $output .= 'td class=menuitem_inactive onmouseover=menuHover(\'mainmenu\', '.$m.', \'menuitem_active\') onmouseout=menuHover(\'mainmenu\', '.$m.', \'menuitem_inactive\') a href='.$framework-output- get_config_vars('Address').$modules[$i]['moduleController'].'/ '.$modules[$i]['modulePath'].''; } if($framework-output-get_config_vars('modulename'.str_replace(' ','',$modules[$i]['moduleName']))) { $output .= $framework-output- get_config_vars('modulename'.$modules[$i]['moduleName']); } else { $output .= $modules[$i]['moduleName']; } $output .= '/a/td'; if($i $c) { $output .= 'td class=menuspacer|/td'; } $m++; $m++; } $output .= '/tr/table'; return $output; The problem is that when I delete an specific array, it outputs something like this: ( [0] = Array ( [moduleId] = 4 [moduleName] = Contents [modulePath] = contents [moduleAliasPath] = [moduleController] = administration [moduleLevel] = 5 [moduleOrder] = 0 [moduleVisibility] = 1 [moduleType] = none [moduleStatus] = 1 ) [2] = Array ( [moduleId] = 1 [moduleName] = System [modulePath] = system [moduleAliasPath] = [moduleController] = administration [moduleLevel] = 5 [moduleOrder] = 2 [moduleVisibility] = 1 [moduleType] = default [moduleStatus] = 1 ) [3] = Array ( [moduleId] = 2 [moduleName] = Logout [modulePath] = logout [moduleAliasPath] = [moduleController] = administration [moduleLevel] = 5 [moduleOrder] = 3 [moduleVisibility] = 1 [moduleType] = alias [moduleStatus] = 1 ) ) So, the question, how resort the numeric values to 1,2,3,4? Regards, Bruno -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php