开发者

Reverse order on output of custom values

开发者 https://www.devze.com 2023-01-06 19:16 出处:网络
I am pulling out values from a开发者_C百科 series of custom fields named thumb: <?php $mykey_values = get_post_custom_values(\'preview\');

I am pulling out values from a开发者_C百科 series of custom fields named thumb:

<?php
      $mykey_values = get_post_custom_values('preview');
      foreach ( $mykey_values as $key => $value ) {
      echo "<img src='$value' width='590'  />";
      }
?>

How do I reverse the order of the output?


array_reverse:

  $mykey_values = array_reverse(get_post_custom_values('preview'));
  foreach ( $mykey_values as $key => $value ) {
  echo "<img src='$value' width='590'  />";
  }


Your best bet is probably array_reverse right before your foreach.

http://php.net/manual/en/function.array-reverse.php


Use array_reverse.

<?php
      $mykey_values = get_post_custom_values('preview');
      $reversed_mykey_values = array_reverse($mykey_values);
      foreach ( $reversed_mykey_values as $key => $value ) {
      echo "<img src='$value' width='590'  />";
      }
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消