6
I have a problem with the in_array function.
I made a var_dump() in the array I want to search for:
array(2) { 
    ["28c8edde3d61a0411511d3b1866f0636"]=> array(8) { 
        ["id"]=> string(32) "c4ca4238a0b923820dcc509a6f75849b" 
        ["qty"]=> float(1) 
        ["price"]=> float(2500) 
        ["name"]=> string(13) "Album: Xim-ER" 
        ["type"]=> string(5) "Asset" 
        ["weight"]=> string(3) "115" 
        ["rowid"]=> string(32) "28c8edde3d61a0411511d3b1866f0636" 
        ["subtotal"]=> float(2500) 
    } 
    ["dc74f1aaf0e81b424c56cbd906f3d3c3"]=> array(8) { 
        ["id"]=> string(33) "Dc4ca4238a0b923820dcc509a6f75849b" 
        ["qty"]=> float(1) 
        ["price"]=> float(2000) 
        ["name"]=> string(21) "Album: Xim-ER Digital" 
        ["type"]=> string(7) "Digital" 
        ["weight"]=> string(1) "0" 
        ["rowid"]=> string(32) "dc74f1aaf0e81b424c56cbd906f3d3c3" 
        ["subtotal"]=> float(2000) 
    }
}
I need to see in this Array if I have Asset, so I did the following in my controller:
<?php
$order->Shipping = new stdClass ();
if (in_array ( array ('type','Asset'), $cart_array )) {
    $order->Shipping->Type = 'Correios';
    $order->Shipping->SourceZipCode = '25670202';
    $order->Shipping->TargetZipCode = $this->session->userdata ( 'user_cep' );
    $order->Shipping->Address = new stdClass ();
    $order->Shipping->Address->Street = $this->session->userdata ( 'user_adress' );
    $order->Shipping->Address->Number = $this->session->userdata ( 'user_adress_number' );
    $order->Shipping->Address->Complement = $this->session->userdata ( 'user_adress_comp' );
    $order->Shipping->Address->District = $this->session->userdata ( 'user_adress_district' );
    $order->Shipping->Address->City = $this->session->userdata ( 'user_city' );
    $order->Shipping->Address->State = $this->session->userdata ( 'user_state' );
} else {
    $order->Shipping->Type = 'WithoutShipping';
}
But he only returns Shipping with Withoutshipping.
I forgot some parameter to do in_array correctly?
It makes sense, because for the in_array to work a "simple type" is required and the array is complex type, with the array_column, the data type checked by in_array is restricted.
– Ruggi
Observing:
array_columnis only available from PHP 5.5.– bfavaretto