Jadvalni PHP qatoriga qo'shish

CSV importdan bir qator bor. Jadval shunga o'xshash

Array
(
    [0] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CBC
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 4
            [Remark2] => TEST
        )

    [1] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CBD
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 5
            [Remark2] => TEST2
        )

    [2] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CJ
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 5
            [Remark2] => TEST3
        )

    [3] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CL
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 4
            [Remark2] => TEST4
        )

    [4] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CRG
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 4
            [Remark2] => TEST5
        )

    [5] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CRGM
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 4
            [Remark2] => TEST6
        )

    [6] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CRSB
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 4
            [Remark2] => TEST7
        )

)

Lekin endi sessiya qo'shishni xohlayman. Shunday qilib, My Array, bu loke ko'rinadi.

[0] => Array
        (
            [DOCategory] => IM
            [ToCustomerCode] => M-CBC
            [ExternalDocNo] => DRDOC-DJ-GBAR10-25
            [Item] => S160373
            [Quantity] => 4
            [Remark2] => TEST
            [session] => ....
        )

[sessiya] bu holatdan

$random = md5(uniqid( $userlogin, true));
$new = array('session' => $random);

Keyin men hozirga qadar harakat qilaman

 $x=0;
                    while( ($line = fgetcsv($f)) !== false) {
                        $data[] = $line;
                    }
                    for($x=0;$x";print_r($newArray);

and the result from my echo "

";print_r($newArray); is 8. So how can i achieve that i want. Thanks in advance and sorry for my bad english.
0
Nima uchun faqatgina oldinga yoki foreach so'zini qator orqali yineleme va sessiya kalitini/qiymatini qo'shish uchun ishlatmaslik kerak?
qo'shib qo'ydi muallif pteronewone, manba

6 javoblar

Ushbu funktsiyadan foydalanasiz

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

   $arr1= array_merge($arr1, $arr2);
</div> </div>
1
qo'shib qo'ydi
[Code] [>] [>] S160373 [Miqdori] => M-CRSB [ExternalDocNo] => DRDOC-DJ-GBAR10-25 [Mavzu] => > 4 [Remark2] => TEST7) [sessiya] => e3ba1d241080830f2638be5a91debd69
qo'shib qo'ydi muallif YVS1102, manba
iltimos, muammo haqida yanada aniqroq aytaylik, men mobil veb-dan foydalanaman, shuning uchun aniq ko'rib chiqa olmayman
qo'shib qo'ydi muallif Chien_Khmt, manba

Sizning kodingiz g'alati, lekin buni sinab ko'ring:

$x=0;
while( ($line = fgetcsv($f)) !== false) {
   $data[] = $line;
}
for($x=0;$x";print_r($newArray);

kerak bo'lmasa temp qatorni atlayabilirsiniz:

$x=0;
while( ($line = fgetcsv($f)) !== false) {
   $data[] = $line;
}
for($x=0;$x";print_r($data);
1
qo'shib qo'ydi
Men hali bu qismga kerak: $ newArray [] = array_combine ($ data [0], $ data [$ x]);
qo'shib qo'ydi muallif YVS1102, manba
OK, shuning uchun qatorni keyingi qatorga qo'shing. $ newArray [$ x] ["session"] = $ new;
qo'shib qo'ydi muallif gbolo, manba
@ YVS1102 javobingizni qabul qiling, agar u sizga ishlagan bo'lsa ...
qo'shib qo'ydi muallif gbolo, manba

array_map() yoki foreach yoki array_walk dan foydalaning va sessiya kalitini qo'shing.

array_map(function($v){
  $v['session'] = md5(uniqid( $userlogin, true));
  return $v;
});
0
qo'shib qo'ydi

You can use array_walk

Buni sinab ko'ring

array_walk($array, function(&$a) {
  $a['session'] = md5(uniqid( $userlogin, true));
});
0
qo'shib qo'ydi

You may use PHP array function array_merge() Here is link

0
qo'shib qo'ydi

Sizning qatoringizdan o'tib, sessiya indeksini qo'shing

for($x=0;$x
0
qo'shib qo'ydi
Bu birinchi javob berdim :(
qo'shib qo'ydi muallif gbolo, manba
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin