Link to home
Start Free TrialLog in
Avatar of denny3d
denny3d

asked on

search and delete a blank value into array php

Hello EE

I have an array like this:
Array
(
    [0] => 1709A

    [1] =>
}

How I find the blank value and delete it?
Avatar of Anwar Saiah
Anwar Saiah

What kind of an array is this, string or what?
If this is string for example you start a loop that checks if the value is empty (null) delete it.
for ($i=0 ; $i< array_length; $i++)
if(Array[$i] == '') delete Array[$i]

or something like this.

Note this is only pseocode
This will do it.
foreach($array as $key => $val)  {
  if($val == "")
   {
     unset($array[$key]);
    }
}

Open in new window

is a bit faster using array functions like array_filter() instead of iteration(for, foreach) like above examples. See below
<?php
 
$your_array = array();
 
$new_array = array_filter($your_array,create_function('$elem', 'return ($elem=="") ? "" : $elem;'));
 
print_r($new_array);
 
?>

Open in new window

Avatar of denny3d

ASKER

the first and secon solution dont work

this is my array:

Array
(
    [0] => 1302                            11022009             132V4

    [1] => 00000056

    [2] => 3+3/3+3BE       00001SERRAMENTI R000640                         Y       2           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [3] => 3+3/3+3BE       00002SERRAMENTI R000640                         Y       2           618.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [4] => 3+3/3+3BE       00003SERRAMENTI R000640                         Y       2           603.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [5] => 4/4BE           00004SERRAMENTI R000640                         Y       3           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [6] => 4/4BE           00005SERRAMENTI R000640                         Y       1           718.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [7] => 3+3/3+3BE       00006SERRAMENTI R000640                         Y       2           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [8] => 3+3/3+3BE       00007SERRAMENTI R000640                         Y       2           618.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [9] => 3+3/3+3BE       00008SERRAMENTI R000640                         Y       2           603.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [10] => 4/4BE           00009SERRAMENTI R000640                         Y       1           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [11] => 4/4BE           00010SERRAMENTI R000640                         Y       1           718.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [12] => 4/4BE           00011SERRAMENTI R000640                         Y       1           818.0  1055.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [13] => 3+3/3+3BE       00012SERRAMENTI R000640                         Y       3           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [14] => 3+3/3+3BE       00013SERRAMENTI R000640                         Y       4           653.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [15] => 3+3/3+3BE       00014SERRAMENTI R000640                         Y       2           603.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [16] => 3+3/3+3BE       00015SERRAMENTI R000640                         Y       2           553.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [17] => 3+3/3+3BE       00016SERRAMENTI R000640                         Y       2           413.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [18] => 4/4BE           00017SERRAMENTI R000640                         Y       2           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [19] => 4/4BE           00018SERRAMENTI R000640                         Y       6           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [20] => 4/4BE           00019SERRAMENTI R000640                         Y       2           603.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [21] => 3+3/3+3BE       00020SERRAMENTI R000640                         Y       4           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [22] => 4/4BE           00021SERRAMENTI R000640                         Y       1           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [23] => 4/4BE           00022SERRAMENTI R000640                         Y       2           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [24] => 4/4BE           00023SERRAMENTI R000640                         Y       2           603.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [25] => 3+3/3+3BE       00024SERRAMENTI R000640                         Y       1           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [26] => 3+3/3+3BE       00025SERRAMENTI R000640                         Y       4           553.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [27] => 4/4BE           00026SERRAMENTI R000640                         Y       1           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [28] => 4/4BE           00027SERRAMENTI R000640                         Y       2           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [29] => 4/4BE           00028SERRAMENTI R000640                         Y       4           603.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [30] => 4/4BE           00029SERRAMENTI R000640                         Y       1           518.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [31] => 4/4BE           00030SERRAMENTI R000640                         Y       1           818.0  1055.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [32] => 3+3/3+3BE       00031SERRAMENTI R000640                         Y       1           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [33] => 3+3/3+3BE       00032SERRAMENTI R000640                         Y       2           553.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [34] => 4/4BE           00033SERRAMENTI R000640                         Y       2           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [35] => 4/4BE           00034SERRAMENTI R000640                         Y       2           603.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [36] => 3+3/3+3BE       00035SERRAMENTI R000640                         Y       3           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [37] => 3+3/3+3BE       00036SERRAMENTI R000640                         Y       1           618.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [38] => 3+3/3+3BE       00037SERRAMENTI R000640                         Y       2           603.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [39] => 4/4BE           00038SERRAMENTI R000640                         Y       2           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [40] => 4/4BE           00039SERRAMENTI R000640                         Y       1           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [41] => 3+3/3+3BE       00040SERRAMENTI R000640                         Y       2           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [42] => 3+3/3+3BE       00041SERRAMENTI R000640                         Y       2           653.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [43] => 3+3/3+3BE       00042SERRAMENTI R000640                         Y       4           603.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [44] => 3+3/3+3BE       00043SERRAMENTI R000640                         Y       2           413.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [45] => 3+3/3+3BE       00044SERRAMENTI R000640                         Y       2           618.0  1660.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [46] => 4/4BE           00045SERRAMENTI R000640                         Y       2           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [47] => 4/4BE           00046SERRAMENTI R000640                         Y       4           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [48] => 4/4BE           00047SERRAMENTI R000640                         Y       6           603.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [49] => 4/4BE           00048SERRAMENTI R000640                         Y       1           518.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [50] => 3+3/3+3BE       00049SERRAMENTI R000640                         Y       1           818.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [51] => 3+3/3+3BE       00050SERRAMENTI R000640                         Y       2           603.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [52] => 3+3/3+3BE       00051SERRAMENTI R000640                         Y       6           553.0  2060.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [53] => 3+3/3+3BE       00052SERRAMENTI R000640                         Y       4           618.0  1660.012                                                                              U=1,6 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [54] => 4/4BE           00053SERRAMENTI R000640                         Y       1           818.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [55] => 4/4BE           00054SERRAMENTI R000640                         Y       5           618.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [56] => 4/4BE           00055SERRAMENTI R000640                         Y       6           603.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [57] => 4/4BE           00056SERRAMENTI R000640                         Y       1           518.0  1130.015                                                                              U=1,4 W/mqýK                    0058/09                                                                                                                                                                                                                                                                                                  

    [58] =>

)


I need to delete key 58
can you show us your php code that its not working as i just tested my code and its ok. Cheers
Avatar of denny3d

ASKER

this is the code
<?php
if(isset($_FILES['test'])){
    if(($_FILES['test']['size'] / 1024) < 500){
       	$array_file = file($_FILES['test']['tmp_name']);
		
		#cancello i valori bianchi nell'array
		
 
$new_array = array_filter($array_file,create_function('$elem', 'return ($elem=="") ? "" : $elem;'));
 
 
 
		
		}
		
		echo '<pre>';
		print_r ($array_file);
		print_r ($new_array);
		echo '</pre>';
	}
		
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ionut A. Tudor
Ionut A. Tudor
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial