PHP-Programmierer chatten hier
Guest
PHP -Array -Suche und löschen
Post
by Guest » 10 Feb 2025, 03:22
Ich habe zwei Array: < /p>
Array 1: < /p>
Code: Select all
Array ( [0] => Array ( [id] => et1 [supplier_id] => 4 [supplier_product_code] => 00054X [is_active] => 1 )
[1] => Array ( [id] => et2 [supplier_id] => 4 [supplier_product_code] => 000558 [is_active] => 1 )
[2] => Array ( [id] => et3 [supplier_id] => 5 [supplier_product_code] => 00054X [is_active] => 1 ));
< /code>
Array 2: < /p>
Array ( [0] => Array ([id] => et1 [same_sku] => et3);
< /code>
Ich muss in Array1 von Array2 alle gleiche_skus löschen. < /p>
Aus meinem Ergebnisarray muss ich Array1 sein: < /p>
Array ( [0] => Array ( [id] => et1 [supplier_id] => 4 [supplier_product_code] => 00054X [is_active] => 1 )
[1] => Array ( [id] => et2 [supplier_id] => 4 [supplier_product_code] => 000558 [is_active] => 1 ));
< /code>
Code, den ich gerade habe, funktioniert nicht. < /p>
public function search_array($array, $val)
{
foreach ($array as $key => $row)
{
if ($row['id'] === $val)
{
return $key;
}
}
}
foreach($array2->result() as $row)
{
$id = $row->id;
$same_sku = $row->same_sku;
$key = $this->search_array($array1, $id);
if(!empty($key))
{
$same_sku_key = $this->search_array($array1, $same_sku);
if(!empty($same_sku_key))
unset($array1[$same_sku_key]);
}
}
1739154154
Guest
Ich habe zwei Array: < /p> Array 1: < /p> [code]Array ( [0] => Array ( [id] => et1 [supplier_id] => 4 [supplier_product_code] => 00054X [is_active] => 1 ) [1] => Array ( [id] => et2 [supplier_id] => 4 [supplier_product_code] => 000558 [is_active] => 1 ) [2] => Array ( [id] => et3 [supplier_id] => 5 [supplier_product_code] => 00054X [is_active] => 1 )); < /code> Array 2: < /p> Array ( [0] => Array ([id] => et1 [same_sku] => et3); < /code> Ich muss in Array1 von Array2 alle gleiche_skus löschen. < /p> Aus meinem Ergebnisarray muss ich Array1 sein: < /p> Array ( [0] => Array ( [id] => et1 [supplier_id] => 4 [supplier_product_code] => 00054X [is_active] => 1 ) [1] => Array ( [id] => et2 [supplier_id] => 4 [supplier_product_code] => 000558 [is_active] => 1 )); < /code> Code, den ich gerade habe, funktioniert nicht. < /p> public function search_array($array, $val) { foreach ($array as $key => $row) { if ($row['id'] === $val) { return $key; } } } foreach($array2->result() as $row) { $id = $row->id; $same_sku = $row->same_sku; $key = $this->search_array($array1, $id); if(!empty($key)) { $same_sku_key = $this->search_array($array1, $same_sku); if(!empty($same_sku_key)) unset($array1[$same_sku_key]); } } [/code]
0 Replies
1 Views
Last post by Anonymous
12 Mar 2025, 13:06
0 Replies
0 Views
Last post by Anonymous
23 Feb 2025, 17:51
0 Replies
11 Views
Last post by Guest
13 Jan 2025, 11:08
0 Replies
14 Views
Last post by Anonymous
12 Feb 2025, 05:07
Echo -Array -Daten druckt nur "Array" druckt "Array".
by
Anonymous »
25 Feb 2025, 19:15 » in
Php
Ich habe ein Problem gestoßen, als ich versucht habe, einem Array über eine Foreach -Schleife Werte hinzuzufügen. Zwei Radio-Buttons pro Thema. Ich möchte dann die Likes und die Abneigungen in zwei...
0 Replies
0 Views
Last post by Anonymous
25 Feb 2025, 19:15