我正在尝试做的事情:
以这种方式在以逗号分隔的单个字符串上获取名称列表(如果有多个):
Britney Spears,
Lady Gaga,
Miley Cyrus
这是怎么回事:
- 我们在一个循环中。
- 我正在尝试将这些
celebrities
与帖子相关联ID
所以我们$id
对每个循环都有这个独特的。一个ID可以附加
多个名人姓名。
询问:
$array = $wpdb->get_results("SELECT name
FROM celebrities
WHERE id = " . $id . "");
PHP代码:
if (is_array($array) && $array != null) {
foreach($array as $single) {
$array = $single->name . ',';
}
}
else {
$array = $array->name;
}
问题:
使用我的代码,我被限制为每个循环一个名人(即使数据库显示另一个名人也应该在场)。
我真的只想检查是否存在多个名人name
,然后将它们放在一个用逗号分隔的字符串中。
期望的输出:
这是我要完成的工作的简单概述:
array(0)
(没有名人) =// SHOW NOTHING
array(1)
(找到一个名人名字) =echo $name
array(2)
(不止一位名人) =foreach($names as $name)
var_dump:
我真的只想向您展示数组结构的复杂性:
array(0) {}
array(1) {
[0] = >
object(stdClass) #1620 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1683 (1) {
["name"]= >
string(6)
"Madonna"
}
[1] = >
object(stdClass) #1611 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1614 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1690 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1598 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(4) {
[0] = >
object(stdClass) #1722 (1) {
["name"]= >
string(6)
"Madonna"
}
[1] = >
object(stdClass) #1706 (1) {
["name"]= >
string(6)
"Madonna"
}
[2] = >
object(stdClass) #1668 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[3] = >
object(stdClass) #1663 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(4) {
[0] = >
object(stdClass) #1615 (1) {
["name"]= >
string(6)
"Madonna"
}
[1] = >
object(stdClass) #1708 (1) {
["name"]= >
string(6)
"Madonna"
}
[2] = >
object(stdClass) #1723 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[3] = >
object(stdClass) #1726 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1598 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1663 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1722 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1734 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1598 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1750 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1751 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1716 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1776 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1795 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1647 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1784 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1776 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1611 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1676 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1781 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(0) {}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1715 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1813 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1826 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1828 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1717 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1765 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1769 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1848 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1690 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1660 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1821 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1717 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1766 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1836 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1765 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1826 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1843 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(2) {
[0] = >
object(stdClass) #1854 (1) {
["name"]= >
string(6)
"Madonna"
}
[1] = >
object(stdClass) #1820 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1814 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1847 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1866 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1820 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1814 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1847 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(2) {
[0] = >
object(stdClass) #1875 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1821 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1786 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1880 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1746 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1815 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1817 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1811 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1874 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1819 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1798 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1820 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1802 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1853 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1741 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1867 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1820 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1688 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1919 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1889 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1923 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1927 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1811 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1904 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1910 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1889 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1927 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1904 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(1) {
[0] = >
object(stdClass) #1843 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1860 (1) {
["name"]= >
string(6)
"Miley Cyrus"
}
}
array(2) {
[0] = >
object(stdClass) #1889 (1) {
["name"]= >
string(5)
"Beyonce"
}
[1] = >
object(stdClass) #1684 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1843 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1811 (1) {
["name"]= >
string(5)
"Beyonce"
}
[1] = >
object(stdClass) #1900 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1904 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1926 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1915 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1829 (1) {
["name"]= >
string(5)
"Beyonce"
}
[1] = >
object(stdClass) #1932 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(0) {}
array(2) {
[0] = >
object(stdClass) #1889 (1) {
["name"]= >
string(6)
"Madonna"
}
[1] = >
object(stdClass) #1952 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(0) {}
array(0) {}
array(2) {
[0] = >
object(stdClass) #1915 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1829 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1932 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1892 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(3) {
[0] = >
object(stdClass) #1899 (1) {
["name"]= >
string(5)
"Beyonce"
}
[1] = >
object(stdClass) #1929 (1) {
["name"]= >
string(5)
"Beyonce"
}
[2] = >
object(stdClass) #1805 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1886 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1829 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1802 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(2) {
[0] = >
object(stdClass) #1932 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1941 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1836 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(1) {
[0] = >
object(stdClass) #1947 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1917 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1954 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1902 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(1) {
[0] = >
object(stdClass) #1836 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(2) {
[0] = >
object(stdClass) #1970 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1842 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(0) {}
array(1) {
[0] = >
object(stdClass) #1878 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(2) {
[0] = >
object(stdClass) #1802 (1) {
["name"]= >
string(5)
"Beyonce"
}
[1] = >
object(stdClass) #1969 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1961 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(2) {
[0] = >
object(stdClass) #1836 (1) {
["name"]= >
string(6)
"Madonna"
}
[1] = >
object(stdClass) #1970 (1) {
["name"]= >
string(5)
"Beyonce"
}
}
array(1) {
[0] = >
object(stdClass) #1902 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
}
array(1) {
[0] = >
object(stdClass) #1979 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1860 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(1) {
[0] = >
object(stdClass) #1946 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(3) {
[0] = >
object(stdClass) #1926 (1) {
["name"]= >
string(10)
"Lady Gaga"
}
[1] = >
object(stdClass) #1848 (1) {
["name"]= >
string(5)
"Beyonce"
}
[2] = >
object(stdClass) #1912 (1) {
["name"]= >
string(6)
"Madonna"
}
}
array(0) {}
我相信我会无缘无故地感到困惑,但我被困住了。