2
print "<pre>";
print_r($arr);
print "</pre>";

Result:

Array
(
    [0] => Array
        (
            [home_id] => 51
            [0] => 51
            [home_what] => bann
            [1] => bann
            [home_artid] => 
            [2] => 
            [home_bannid] => 27
            [3] => 27
       )
   [1] => Array
       (. . . etc

How to get the result without index - value lines? Like this:

[home_id] => 51
[home_what] => bann
[home_artid] => 
[home_bannid] => 27

lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum

1
  • Use mysqli_fetch_assoc(). Commented Jul 29, 2018 at 8:31

2 Answers 2

1

You can try array_map with array_unique

Snippet

$arr = [['home_id' => 51,
            '0' => 51,
            'home_what' => 'bann',
            '1' => 'bann',
            'home_artid' => '',
            '2' => '',
            'home_bannid' => 27,
            '3' => 27]];
$result = array_map("array_unique", $arr);
print_r($result);

Output

Array
(
    [0] => Array
        (
            [home_id] => 51
            [home_what] => bann
            [home_artid] => 
            [home_bannid] => 27
        )

)

Live demo

Read more about

array_map

array_unique

Note: If your data is coming from database, You can use mysqli_fetch_assoc instead.

Sign up to request clarification or add additional context in comments.

4 Comments

@puerto probably you are using mysqli_fetch_array() somewhere, hence it is giving you both numeric and associative keys. If you had used mysqli_fetch_assoc() , you won't be needing any extra PHP functions.
@vivek_23 Since, question isn't tagged as mysql, array may be from somewhere else. This will work in this case.
@Smartpal Yes your code is correct, but if the author had provided more context, he wouldn't have to do anything extra.
@vivek_23 Yes, I've noted your point (mysqli_fetch_assoc) in my answer. :)
0

Why don't you use a simple foreach loop and print it.

$arr = array(1,2,3,4,5);

foreach($arr as $arr_item){

   echo $arr_item;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.