php - 如何从关联 PHP 数组中获取 First to End 项?
问题描述
如果我有一个像这样的数组:
$fuel[0]->fuel_qty = 1.00
$fuel[1]->fuel_qty = 2.00
以下函数获取数组的第一个元素 (1.00)。
public function printFuel($id) {
$fuel = $this->Fuel_model->directFuelQtyById($id);
$this->amount_word = $this->convert_number_to_words($fuel[0]->fuel_qty) . '<br>'." Only";
}
我想通过修改这个函数来获取所有的数组元素(1.00、2.00 等)。我怎么能得到这个。谁能帮我?
解决方案
要获取最后一个元素,请使用 array_pop:https ://www.php.net/manual/en/function.array-pop.php
要获取第一个元素,请使用 array_shift:https ://www.php.net/manual/en/function.array-shift.php
推荐阅读
- python - Numpy 从具有索引数组的二维数组中获取一维数组
- javascript - Reactjs:如何使用 JSZip 从 zip 文件中只获取一个文件?
- model - 在 Blender 中否定零件并错误导出
- python - 在 MQTT 中强制断开连接(触发最后遗嘱消息)
- django - DJANGO 3.1 'crispy_forms_tags' 不是注册标签库
- laravel-artisan - 安装 php artisan swagger 时出错:生成 Ubuntu
- android - Android 应用内购买有效订单但在 Google Play 商店中不存在
- javascript - Ngrx createReducer 从早期版本迁移
- sql - Redshift:Coalesce 无法按预期工作
- python - 是否可以矢量化 scipy Dirichlet PDF 函数?