将数据从数据库中提取到php数组中

将数据从数据库中提取到php数组中

问题描述:

I've created an array of categories in php like this:

$cats=array("Coffee", "Beverages", "Drinks", "Snacks/Desserts");

But I want to make it like dynamic. Let's say when I update my database via my website (delete-change name-add a new category), I need this array to follow those updates.

Is is possible? Or else, how can I deal with it?

我在php中创建了一个类别数组,如下所示: p>

   $ cats = array(“Coffee”,“Beverages”,“Drinks”,“Snacks / Desserts”); 
  code>  pre> 
 
 

但我想要它 喜欢动态。 假设当我通过我的网站更新我的数据库时(删除 - 更改名称 - 添加一个新类别),我需要这个数组来跟踪这些更新。 p>

可能吗? 否则,我该如何处理呢? p> div>

You can indeed, just use array_push() !

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

It pushes your passed variables to the end of the Array, and it increases its size.

No. Array can not follow your updates. But you can create the array based on database content. Which is usually what all sites do.