【问题标题】:array with all my loops inside包含我所有循环的数组
【发布时间】:2016-01-02 04:40:04
【问题描述】:

我有这个 wordpress 循环,我想用所有变量构建一个循环...我的问题我的 $array_data 只存储最后一个循环而不是全部...我如何将所有循环存储在我的 @987654322 @ 大批 ?

  foreach($adicionados as $post) :

$nome = simple_fields_values('pname1');
$im = simple_fields_values('ftotop');
$cp=$adicionados ;
$imatop = $im; 
$data=get_sub_field('wallet_data');
$evento=get_sub_field('wallet_evento');
$obs=get_sub_field('wallet_obs');  
$numeros_horas = get_sub_field('Wallet_n_horas');
$valor_horas = get_sub_field('wallet_valorh');
$evento = get_sub_field('wallet_evento');
$horarios = get_sub_field('wallet_horario');
$props=get_sub_field('wallet_props');
$total_parcial = $valor_horas * $numeros_horas."€";
$ii = wp_get_attachment_image($imatop[0]);
$array_valores['promotora'] []=  get_the_ID(); 
$array_valores['valor'][]=$total_parcial;
$nomeid=get_the_ID($nome);



$array_data = array(

  'foto' => $im,
  'data' => $data, 
  'nome' => $nome, 
  'evento' => $evento,
  'horario' => $horario, 
  'numero_horas' => $numero_horas, 
  'valor_horas' => $valor_horas,
  'valor_parcial' => $total_parcial, 
  'obs' => $obs
  );

【问题讨论】:

  • $array_data[] = array(
  • 很高兴听到它的工作:)

标签: php arrays wordpress loops


【解决方案1】:

您看到的是最后一个循环数据,因为每次循环都会存储不同的数据。类似于下面的代码:

$foo = 'one';
$foo = 'two'; // replaces 'one' with 'two'
$foo = 'three'; // replaces 'two' with 'three'

echo $foo; // outputs only 'three'

这里需要一个二维数组。数组数组。

传统上,您会创建一个索引$i,并使用array_data[$i] 存储每个循环的数据,这正是for( $i = 0; $i < count($adicionados); $i++) 的精髓。

但正如评论中提到的,$array_data[] 会为您做到这一点(尽管速度不快)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 2018-05-15
    • 2014-04-23
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多