.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
unsetting array's problem (PHP)
Old
  (#1)
Ancient
PodBot MM's Laziest Waypointer
 
Ancient's Avatar
 
Status: Offline
Posts: 1,010
Join Date: Jan 2005
Location: Nebraska, United States of America
Default unsetting array's problem (PHP) - 16-05-2010

I've hit a bump in the road.

Current Arrays:

$find_user
PHP Code:
Array([0] => Array([0] => 'Ancient', [username] => 'Ancient', [1] => 'Password', [password] => 'password'),
[
1] => Array([0] => 'Ancient2', [username] => 'Ancient2', [1] => 'Password', [password] => 'Password')) 
Right now I'm trying to get rid of [0] => 'Ancient', and just leave [username] => and [password].
The goal is to unset some array #s and keep the array keys.

Goal:
PHP Code:
Array([0] => Array([username] => Ancient, [password] => Password),
[
1] => Array([username] => Ancient2, [password] => Password)) 
What I have now:
PHP Code:
function kill_num_array($item$array false)
            {
                if(!
$array)
                    {
                        
//
                        // Gets rid of numbered arrays.
                        // Example: $find_user[0]['id'] changes to $find_user['id']
                        //
                        
$i 0;
                        while(
count($item[0]) >= $i)
                            {
                                unset(
$item[0][$i]); // Error Log shows this line is bad.
                                
$i++;
                            }
                        unset(
$i);
                        return 
$item[0];
                    }
                else{
                        
//
                        // Gets rid of sub-numbered arrays
                        // Example: $find_user[1][0]  changes to $find_user[1]['some_key']
                        //
                        
$i 0;
                        
$a 0;
                        while(
count($item[$a]) >= $i)
                            {
                                unset(
$item[$a][$i]);
                                
$i++;
                                if(
$i count($item[$a]))
                                    {
                                        
$a++;
                                        
$i 0;
                                    }
                                if(
$a count($item))
                                    {
                                        unset(
$a$i);
                                        exit;
                                    }
                            }
                        continue;
                        return 
$item;
                    }
            } 
To me the function looks fine.
But PHP must really hate me because it's throwing up a bunch of errors now.
What's weird, is that this worked before and now even though I haven't touched it, it's throwing up errors.


EDIT:
After a long time of debugging I finally found the answer.
PHP Code:
function kill_num_array($item$array false)
            {
                if(!
$array)
                    {
                        
//
                        // Gets rid of numbered arrays.
                        // Example: array($find_user[0], $find_user['id']) changes to $find_user['id']
                        //
                        
$i 0;
                        while(
count($item) >= $i)
                            {
                                unset(
$item[$i]);
                                
$i++;
                            }
                        unset(
$i);
                        return 
$item;
                    }
                else{
                        
//
                        // Gets rid of sub-numbered arrays
                        // Example: $find_user[1][0]  changes to $find_user[1]['some_key']
                        //
                        
$i 0;
                        
$a 0;
                        while(
count($item[$a]) >= $i)
                            {
                                unset(
$item[$a][$i]);
                                
$i++;
                                if(
$i >= count($item[$a]))
                                    {
                                        
$a++;
                                        
$i 0;
                                    }
                                if(
$a >= count($item))
                                    {
                                        unset(
$a$i);
                                        exit;
                                    }
                            }
                        continue;
                        return 
$item;
                    }
            } 


[Web Designer][Waypointer][Gamer]
CFE Games Administrator
[CFE]Games.com
[Never Trust the Untrusted]

Last edited by Ancient; 16-05-2010 at 07:35..
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com