I have an index array
$array[0] = 10;$array[1] = 12;...
You may have to make your own function or set up for this. But i did a quicky function that should work fine for your needs:
function remove_element($arr, $val){foreach ($arr as $key => $value){if ($arr[$key] == $val){unset($arr[$key]);}}return $arr = array_values($arr);}You can rename the function if you want.
Thanks again for the help Truefusion. Its too bad PHP does not have a array function for this specific task itself, they seem to have many other functions for other kinds of array modifications.
thanks
Remove A Value From A Php Array Based On Its Value
This is really good... I needed a script to find the only file in a folder, but it returned '.' and '..' and then the file... Now I just do this:
<?php
$return = delete_value($return, '.');
$return = delete_value($return, '..');
?>
Thanks...
-reply by php-freak!
strip element from array()
Remove A Value From A Php Array Based On Its Value
Is there away to chop an array depending on the value of a sub-array?
I.E:
$array[0] = 10;
$array[1] = 12;
$allcontent = array("page1", "page2", array("page3a", "page3b"), "page4", "page5");
If my function finds "page3b" I want it to end the parent array at "page2"/
I.E.:
$allcontent = array("page1", "page2");
If this can't be done how about just removing the sub array?
I.E.: $allcontent = array("page1", "page2", "page4", "page5");
-reply by Scoutman57
PHP 5 has a great function in 'scandir()'
however, to counter the problem noted with '.' and '..' becoming array values, if I simply unset() them, it left array keys with a null value. so I built the array manually instead of using scandir() like so;
$awards_array = array();$dp = opendir ('dir_location'); While ( $item = readdir($dp) ){ if ( $item != '.' && $item != '..' ) { $awards_array[] = $item; }
}
Replying to FeedBacker-reply by Ramsonnehi there... Have been trying to create a 2D array for the Vignere cipher but still I encounter so many errors... Can anyone help... Here is the code have typed so far.
String keyword = "VIGNERE";
char[] keychar = keyword.ToCharArray();
int lenght = keychar.Length;
char [] alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','and','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int len = alphabet.Length;
char [][]vc =new char [lenght][len];
for(int keylenght=0; keylenght<vc.Length; keylenght++){
for(int alpha=0; alpha<vc[keylenght].Length; alpha++){
if(vc[lenght][len]==keychar[lenght]){
vc[lenght][len] =alphabet[len];
vc[lenght][len]++;
System.Err.Print(vc[lenght][len]);
}
}
}
-reply by rollyyou can use array_unshift to push it to the front of the array and then remove with array_shift the first value
You can try unsetting the values that you want to remove.
<?php$array[0] = 10;$array[1] = 12;echo 'At first: ' . $array[0] . ', ' . $array[1];unset($array[1]);echo 'After: ' . $array[0] . ' ' . $array[1] . 'only!';?>
hi,
Why don't do this : ?
Fab
-reply by __fabrice