0

我想组合来自两个数组的前 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;

    }
  }
}

这些阵列的输出是:- 价格 => 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

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

谁能帮我。

4

2 回答 2

0

array_slice组合它们之前的数组。

于 2013-10-04T06:50:59.990 回答
0

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

<?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";
 }

?>
于 2013-10-04T06:46:04.100 回答