我试图根据条件计算某个值出现在多维数组中的次数.这是一个示例数组;
$fruit = array (
"oranges" => array(
"name" => "Orange",
"color" => "orange",
"taste" => "sweet",
"healthy" => "yes"
),
"apples" => array(
"name" => "Apple",
"color" => "green",
"taste" => "sweet",
"healthy" => "yes"
),
"bananas" => array(
"name" => "Banana",
"color" => "yellow",
"taste" => "sweet",
"healthy" => "yes"
),
"grapes" => array(
"name" => "Grape",
"color" => "green",
"taste" => "sweet",
"healthy" => "yes"
)
);
Run Code Online (Sandbox Code Playgroud)
如果我想要显示所有绿色水果,我可以做以下(让我知道这是否是最好的方式);
for ($row = 0; $row < 3; $row++) { …Run Code Online (Sandbox Code Playgroud) 如果服务器 1 有我的数据库和 Memcached 以及 www.website1.co.uk - 该网站将正常工作。
但如果我有以下场景怎么办:
Server 1 - Database - Memcached - website1.co.uk
Server 2 - website2.co.uk
Server 3 - website3.co.uk
Run Code Online (Sandbox Code Playgroud)
我该如何设置,以便 website2 和 website3 都可以连接、读取和写入服务器 1 上的 memcached 数据库(它们已经可以连接到服务器 1 并在没有 memcache 的情况下读取和写入数据库)。
我是否需要在服务器 2 和服务器 3 上安装 Memcache 才能连接?
我以前从未使用过内存缓存,所以这是一次学习经历。
我正在尝试包含一个文件,但它似乎不起作用 - 这是整个代码:
if (file_exists('config/categories.php')) {
include ('config/categories.php');
}
foreach ($categories as $cat_sef => $cat_name) {
echo '<a href="'.$full_domain.$cat_sef.'" alt="#">'.$cat_name.'</a><br />';
}
Run Code Online (Sandbox Code Playgroud)
config/categories.php的内容只是一个数组:
$categories = array("category-1" => "Category 1",
"category-2" => "Category 2",
"category-3" => "Category 3")
Run Code Online (Sandbox Code Playgroud)
我知道该文件存在,因为以下工作原理:
if (file_exists('config/categories.php')) {
echo "file exists";
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将categories.php中的数组替换为:
echo "testing";
Run Code Online (Sandbox Code Playgroud)
什么都不会显示.因此,据我所知,该文件存在但似乎并没有包括一些如何.如果我将类别文件重命名为其他内容,我将收到"无此文件"错误(文件不存在).
使用原始代码段,我得到的错误是:
Notice: Undefined variable: categories
Run Code Online (Sandbox Code Playgroud)
但正如您所看到的,它在categories.php文件中定义.
它唯一的工作方式是将数组放在我的代码的if(file_exists)部分的位置,我不想这样做,因为其他部分依赖于那些categories.php文件,所以我不想欺骗多个文件中的数组.
有谁知道这可能是什么?如果您需要更多信息,请告诉我.