如何使用两个数组组合前 6 个元素


How to combine first 6 elements using two arrays

我想组合两个数组中的前 6 个元素。

我使用以下代码来组合数组。

$combined = array_combine($models,$prices);

这是$models数组

if (!is_null($elements)) {
    foreach ($elements as $element) {
        $nodes = $element->childNodes;
        foreach ($nodes as $node) {
            $modle = $node->nodeValue;
            $modle1 = basename($modle); 
            $models[] = $modle1;
        }
    }
}

这是$prices数组

if (!is_null($price)) {
  foreach ($price as $p) {
    $nodes1 = $p->childNodes;
    foreach ($nodes1 as $node1) {
      $modlePrice = trim($node1->nodeValue,'Regular Price:');
      $modlePrice1 = basename($modlePrice); 
      $prices[] = $modlePrice1;
    }
  }
}

这些数组的输出是:-价格 => 斯里兰卡卢比 295,000.00 斯里兰卡卢比 395,000.00 斯里兰卡卢比 290,000.00 斯里兰卡卢比 150,000.00 斯里兰卡卢比 68,000.00 斯里兰卡卢比 45,000.00 斯里兰卡卢比 31,000.00 斯里兰卡卢比 340,000.00

modles => 三星 40" UA40 ES6220 系列 6 智能 3D LED 电视,带 4 个眼镜三星 55 英寸 F8000 系列 8 智能 3D 全高清 LED 电视三星 46 英寸 F8000 系列 8 智能 3D 全高清 LED 电视三星 40" F6400 系列 6 智能 3D 全高清 LED 电视等...

谁能帮我。

在组合数组之前array_slice数组。

尝试下面的代码,如果有任何问题,请告诉我..等待您的重播...

<?php
    // Your Price Result
 $prices = array('LKR 295,000.00','LKR 395,000.00',' LKR 290,000.00',' LKR 150,000.00',' LKR 68,000.00',' LKR 45,000.00',' LKR 31,000.00 ','LKR 340,000.00');
    // Your Modles Results
 $models = array('Samsung 40" UA40 ES6220 Series 6 SMART 3D LED TV with 4 glasses',' Samsung 55" F8000 Series 8 Smart 3D Full HD LED TV ','Samsung 46" F8000 Series 8 Smart 3D Full HD LED TV',' Samsung 40" F6400 Series 6 Smart 3D Full HD LED TV',' Samsung 40" F6400 Series 6 Smart 3D Full HD LED TV' ,' Samsung 48" F6400 Series 4 Smart 3D LED TV' ,' Samsung 48" F6400 Series 6 Smart 2D HD LED TV' ,' Samsung 42" F6400 Series 6 Smart 4D Full HD LED TV'  ); 

 if(sizeof($prices) == sizeof($models)){
 $combined = array_combine($models,$prices);
 echo "<pre>";
 print_r($combined);
 echo "</pre>";
 exit;
 }else{
    echo "Length of array are not same";
 }
?>