0

I want to retrieve or check whether the "ket_upload" key contains "cash" or "credit" values. Do you have any suggestions?

The data is like this :

Array (
    [0] => Array (
        [kd_upber] => 54 
        [kd_p] => 35 
        [kd_r] => 16 
        [harga] => 128000000 
        [type] => 64 Plus 
        [lokasi] => Ds. PENTADIO BARAT, KEC. TELAGA BIRU 
        [blok] => D 
        [no_rumah] => 1 
        [ket_upload] => credit 
        [ktp] => NULL 
        [npwp] => NULL 
        [kk] => NULL
        [skbm] => NULL 
        [buku_nikah] => NULL 
        [kpr] => NULL 
        [tanggal] => 2020-12-31 : 08:19:39
    ) 
    [1] => Array ( 
        [kd_upber] => 55 
        [kd_p] => 35 
        [kd_r] => 17 
        [harga] => 150000000 
        [type] => 64 Plus 
        [lokasi] => Ds. PENTADIO BARAT, KEC. TELAGA BIRU 
        [blok] => E 
        [no_rumah] => 1 
        [ket_upload] => cash 
        [ktp] => NULL 
        [npwp] => NULL 
        [kk] => NULL 
        [skbm] => NULL 
        [buku_nikah] => NULL 
        [kpr] => NULL 
        [tanggal] => 2020-12-31 : 08:21:47 
    )
)
IGP
  • 14,160
  • 4
  • 26
  • 43

2 Answers2

1

i think you should using function somethings like that ;

function check_has ( $array ) {    
    if( is_array ( $array ) ) { 
        foreach( $array as $key => $value  ) {
        if ($key ==  'ket_upload' and ($value == 'credit' or $value == 'cash')){
                return true;
            }
        }
    }
    return false;
}`
0

Just a suggestion maybe can try this too

foreach($array as $row){
  if($row['ket_upload'] == 'credit' || $row['ket_upload'] == 'cash'){
     #code ...
  }
}

Hope it help ya! also please let me know if there is any error or wrong with my code.

hannn1
  • 61
  • 1
  • 2
  • 6
  • I'm glad that it can help you! – hannn1 Dec 31 '20 at 03:13
  • I'm sorry .. your answer is correct and I've tried it successfully, but I want to find a specific value for example "cash" in the array of keys "ket_upload" but not using a loop. I want to point directly can I? – Rivaldy Saputra Agus Dec 31 '20 at 06:21
  • Sure, just go ahead and try it. haha – hannn1 Dec 31 '20 at 15:09
  • I mean, how can I access those values ​​without foreach? – Rivaldy Saputra Agus Dec 31 '20 at 16:14
  • hmm, if I did not get it wrong you can do it that way too but u need to know the key for the row you want to check or if that any other way that to achieve that. Maybe this https://stackoverflow.com/questions/15093859/get-element-at-n-position-in-an-array-without-loop can help you. – hannn1 Jan 01 '21 at 16:47