update_post_meta()
呼叫update_metadata
从这一行开始:
if ( !$meta_type || !$meta_key )
return false;
我编写了一个简单的测试(使用了大量的剪切和粘贴),以查看如何计算0的字符串值(而不是在PHP手册中查找):
<?php
$meta_key = (string) 0;
if ( ! $meta_key )
echo "0 exits function<br />";
else {
echo "0 remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
echo \'<br />\';
$meta_key = (string) 0;
if ( ! $meta_key )
echo "(string) 0 exits function<br />";
else {
echo "(string) 0 remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
echo \'<br />\';
$meta_key = (string) \'0\';
if ( ! $meta_key )
echo "(string) \'0\' exits function<br />";
else {
echo "(string) \'0\' remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
echo \'<br />\';
$meta_key = 0x0;
if ( ! $meta_key )
echo "0x0 exits function<br />";
else {
echo "0x0 remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
echo \'<br />\';
$meta_key = (string) 0x0;
if ( ! $meta_key )
echo "(string) 0x0 exits function<br />";
else {
echo "(string) 0x0 remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
echo \'<br />\';
$meta_key = \'0x0\';
if ( ! $meta_key )
echo "\'0x0\' exits function<br />";
else {
echo "\'0x0\' remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
echo \'<br />\';
$meta_key = (string) \'0x0\';
if ( ! $meta_key )
echo "(string) \'0x0\' exits function<br />";
else {
echo "(string) \'0x0\' remains in function<br />";
echo " \\$meta_key = $meta_key<br />";
echo " (integer) \\$meta_key = " . (integer) $meta_key . \'<br />\';
}
结果是:
0 exits function
(string) 0 exits function
(string) \'0\' exits function
0x0 exits function
(string) 0x0 exits function
\'0x0\' remains in function
$meta_key = 0x0
(integer) $meta_key = 0
(string) \'0x0\' remains in function
$meta_key = 0x0
(integer) $meta_key = 0
因此,要添加值0,可以将其更改为字符串“0x0”,并在检索时将其转换为整数。0x0是0的二进制(我认为)。