Сделайте массив из двух - PullRequest
       13

Сделайте массив из двух

0 голосов
/ 28 апреля 2010

Я хотел бы создать массив, который сообщает страницам моего сайта, где показывать в PHP.
В $sor["site_id"] у меня есть две или четыре строки длины символов. пример: 23, 42, 13, 1
В моем другом массиве (называемом $pages_show) я хочу передать все site_ids другому идентификатору.

$parancs="SELECT * FROM pages ORDER BY id";
$eredmeny=mysql_query($parancs) or die("Hibás SQL:".$parancs);
while($sor=mysql_fetch_array($eredmeny)) 
{
$pages[]=array(
"id"=>$sor["id"],
"name"=>$sor["name"],
"title"=>$sor["title"],
"description"=>$sor["description"],
"keywords"=>$sor["keywords"]
);
// this makes my pages array with the information about that page.

$shower = explode(", ",$sor["site_id"]);
// this is explode my site_id
$pages_show[]=array(
"id"=>$sor["id"],
"where"=>$shower
//to 'where' i want to put all the explode's elements one-by-one, to get the result like down
);

Этот скрипт дает мне следующий результат:

Array (3)
0 => Array (2)
  id => "29"
  where => Array (2)
    0 => "17"
    1 => "16"
1 => Array (2)
  id => "30"
  where => Array (1)
    0 => "17"
2 => Array (2)
  id => "31"
  where => Array (1)
    0 => "17"

Но в этом случае я бы хотел быть таким:

Array (4)
0 => Array (2)
  id => "29"
  where => "17"
1 => Array (2)
  id => "29"
  where => "16"
2 => Array (2)
  id => "30"
  where => "17"
3 => Array (2)
  id => "31"
  where => "17"

Спасибо за вашу помощь.

Ответы [ 2 ]

3 голосов
/ 28 апреля 2010

Вы должны перебрать массив $shower:

$shower = explode(", ",$sor["site_id"]);
// this is explode my site_id

foreach($shower as $show) {
    $pages_show[]=array("id"=>$sor["id"],"where"=>$show);
}
0 голосов
/ 28 апреля 2010

если $ shower это массив, то $ shower [$ i ++] nem?

...