0

var_dump($myarray);

This is my array output,I tried array_filter then i got all null values.pls help.I want to get 'Federal Bank (India) - Banking','Federal Bank (India) - Banking' from this array,how can i remove null from this.

    null
    null
    null
    null
    null
    string 'Federal Bank (India) - Banking' (length=30)
    null
    null
    null
    string 'Federal Bank (India) - Banking' (length=30)
    null
null
null

I tried array_filer($myarray,'strlen') also,but i did not get it.

11
  • 4
    Show your actual array... Commented Dec 19, 2015 at 7:22
  • Federal Bank (India) - Banking Federal Bank (India) - Banking Commented Dec 19, 2015 at 7:23
  • i cant echo it in a table Commented Dec 19, 2015 at 7:24
  • how i can remove this Commented Dec 19, 2015 at 7:26
  • 1
    Do one thing, Use print_r() instead of var_dump(). And copy result in your question... Commented Dec 19, 2015 at 7:26

4 Answers 4

3

Try array_filter()

$a = [null,'h',null,'g'];
echo '<pre>';
print_r(array_filter($a ,function($a){
        if($a !== null)
            return $a;
    }));
Sign up to request clarification or add additional context in comments.

Comments

0

The array_unique(array) removes duplicate entries, then remove single null

Try;

$array = array_unique($array);
if(($key = array_search("null", $array)) !== false) {
    unset($array[$key]);
}

Comments

0

Just Use array_filter() See more here

Code :

$new_Array=array_filter($old_Array);
print_r($new_Array);

Comments

0

try this. i assumed your array as given below. try to alter your code as required this may help you. let me know the result

<?php
$arr=array("null","null","Federal Bank (India) - Banking","null","null","Federal Bank (India) - Banking");
$str=implode(' ',$arr);
echo $str."<br>";
echo$new_str=str_replace("null","",$str);// replace all null and your expected output
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.