LoginSignup
0
0

More than 1 year has passed since last update.

【PHP】配列の存在チェック if(!empty(array_filter($配列))){

Last updated at Posted at 2023-01-27

連想配列内でどれか一つでも要素が存在するかをチェック

コード

<?php 
$fruits_data = [$fruits['apple'],$fruits['grape'],$fruits['peaches'],$fruits['orange']];?>
if(!empty(array_filter($fruits_data))){?>
    <table>
        <tr>
            <th>りんご</th>
            <th>ぶどう</th>
            <th>ピーチ</th>
            <th>オレンジ</th>
        </tr>
        <tr>
            <td><?php echo $fruits['apple']?:'売り切れ'; ?></td>
            <td><?php echo $fruits['grape']?:'売り切れ'; ?></td>
            <td><?php echo $fruits['peaches']?: '売り切れ'; ?></td>
            <td><?php echo $fruits['orange']?: '売り切れ'; ?></td>
        </tr>
    </table><?php 
}?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0