我一直试图在array_unique没有成功的情况下内爆 2 个变量。这两个变量进行 mysql 调用,每个变量都返回 data ok。放在一个数组中也会返回来自两者的数据,但是,当array_unique它们内爆时,它们有重复的数据,我想在返回时清除这些数据。建议将不胜感激。
$a = 'mysql string 1';// basically words A, B, C
$b = 'mysql string 2';// basically words D, A, E
$a_b_array = array($a, $b);
sort($a_b_array);
$a_b_string = implode("\n", array_unique($a_b_array));
echo $a_b_string; //returns $a and $b with duplicated data
Run Code Online (Sandbox Code Playgroud)
我也试过SORT_REGULAR,不要认为这是问题所在:
//sort($a_b_array);
$a_b_string = implode("\n", array_unique($a_b_array, SORT_REGULAR);
Run Code Online (Sandbox Code Playgroud)
预期结果为:A、B、C、D、E
implode()我有一个关于in 的问题php,我有这个array()
$user_data = array(
'user_id_num' => $_POST['userid'],
'fullname' => $_POST['userfname'],
'username' => $_POST['useruname'],
'password' => $password_hash
);
Run Code Online (Sandbox Code Playgroud)
我想要实现的目标是这样的,例如
对于田野
`user_id_num`,`fullname`,`username`,`password`
Run Code Online (Sandbox Code Playgroud)
和价值观
'2159','Sample Name','example','mypassword' <- hash password
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的是这个
$user_fields = '`' . implode('`, `', $user_data) . '`';
$user_data = '\'' . implode('\', \', $user_data) . '\'';
Run Code Online (Sandbox Code Playgroud)
但我无法得到我想要实现的目标,有人可以帮助我吗?提前致谢
我一直在寻找和挠头几天,我被困在岩石和坚硬的地方之间.在我之前的所有代码运行之后,我留下了这个数组:
Array (
[0] => Array
(
[0] => 1
[1] => 3
)
[1] => Array
(
[0] => 6
[1] => 7
[2] => 8
)
[2] => Array
(
[0] => 9
[1] => 10
)
)
Run Code Online (Sandbox Code Playgroud)
我需要做的是计算所有键的每个可能的排列.
所需的输出需要可以作为单独的记录轻松插入,或者最好是大量插入到sql数据库中.
在我狩猎之后,我尝试了无数的例子.我得到的最接近的是使用Implode函数,但这仍然不起作用.
任何帮助是极大的赞赏!
- 编辑 -
以下是返回数组的外观示例:
Array
(
[0] => 1,6,9
[1] => 1,6,10
[2] => 3,6,9
[3] => 3,6,10
[4] => 1,7,9
[5] => 1,7,10
[6] => 3,7,9,
[7] => 3,7,10
)
Run Code Online (Sandbox Code Playgroud)
这不是每个排列,但应该让你知道我需要实现什么.
$ status的输出
Array
(
[1] => 1
[2] => 0
[3] => 0
[4] => 4
[5] => 4
)
$color_code_string = implode(",",$status);
Run Code Online (Sandbox Code Playgroud)
输出继电器
1,0,0,4,4
$color_code_string = str_replace("0","'#F00'",$color_code_string);
$color_code_string = str_replace("1","'#00bcd4'",$color_code_string);
$color_code_string = str_replace("2","'#4caf50'",$color_code_string);
$color_code_string = str_replace("3","'#bdbdbd'",$color_code_string);
$color_code_string = str_replace("4","'#ff9900'",$color_code_string);
Run Code Online (Sandbox Code Playgroud)
例外
SyntaxError: illegal character
colors: ['#00bcd'#ff9900'','#F00','#F00','#ff9900','#ff9900']
//prints '#00bcd'#ff9900'','#F00','#F00','#ff9900','#ff9900'
Run Code Online (Sandbox Code Playgroud)
如何实现预期输出如下
'#00bcd','#ff9900','#F00','#F00','#ff9900','#ff9900'
Run Code Online (Sandbox Code Playgroud) 我认为它应该不难解决,但我无法得到解决方案。
我试图内爆一个数组以获得这个结果:
$new_array = "755, 646, 648, 260, 257, 261, 271, 764, ..."
Run Code Online (Sandbox Code Playgroud)
这是我的数组:
Array
(
[0] => Array
(
[0] => 755
[1] => 646
)
[1] => Array
(
[0] => 648
[1] => 260
[2] => 257
[3] => 261
)
[2] => Array
(
[0] => 271
)
[3] => Array
(
[0] => 764
[1] => 643
[2] => 260
[3] => 263
[4] => 756
[5] => 763
[6] => 762
[7] => 259 …Run Code Online (Sandbox Code Playgroud) 我试图找出是否有更好的方法来创建对象的子对象的属性列表.(粗略的措辞道歉,我不是一个OO专家)
我有一个对象"事件",其中包含一系列"艺术家",每个艺术家都有一个"artist_name".在我的HTML输出中,我想要一个由逗号分隔的艺术家名称的简单列表.
PHP的implode()似乎是创建以逗号分隔的值列表的最佳方式.我目前正在迭代对象并在临时数组"artistlist"中推送值,因此我可以使用implode().
这是我能想到的最短时间.有没有办法让这更优雅?
$artistlist = array();
foreach ($event->artists as $artist)
{
$artistlist[] = $artist->artist_name;
}
echo implode(', ', $artistlist);
Run Code Online (Sandbox Code Playgroud) 我有一个表单,我有三个这样的复选框:
<td>Wireless <input type="checkbox" name="services[]" value="wireless" /></td>
</tr>
<tr>
<td>Cellular <input type="checkbox" name="services[]" value="cellular" /></td>
</tr>
<tr>
<td>Security <input type="checkbox" name="services[]" value="Security" /></td>
<input type="submit" name="submit">
Run Code Online (Sandbox Code Playgroud)
然后我解压缩($ _ POST),并拥有此代码
$comServices = implode(",", $services);
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
警告:implode()[function.implode]:传入的参数无效..
有谁知道为什么我得到这个错误?
我想只对<code>中要剥离的内容</ code>中的内容运行htmlentities()
我写了一个函数,它接受一个字符串并在<code> </ code>之间找到内容
function parse_code($string) {
// test the string and find contents with <code></code>
preg_match('@<code>(.*?)</code>@s', $string, $matches);
// return the match if it succeeded
if($matches) {
return $matches[1];
}else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
function parse_code($string) {
<div class="myclass" rel="stuff"> things in here </div>
<code> only run htmlentites() here so strip out things like < > " ' & </code>
<div> things in here </div>
但是我需要一些实际运行htmlentities()的函数的帮助; 在<code> </ code>中的内容然后implode()将它们全部重新组合在一起.例如,假设我们在下面有字符串.
// test the string and find contents with …Run Code Online (Sandbox Code Playgroud) 我正在使用Codeigniter及其验证规则 - 自定义回调验证.无论如何,我认为这似乎与CI无关.
我有这个函数返回一个字符串...
function array_implode($a)
{
return implode(',', $a);
}
Run Code Online (Sandbox Code Playgroud)
...但我总是得到一条消息implode():传递的参数无效
但是var_dump()告诉我这个:
array(2) {
[0]=> string(10) "First item"
[1]=> string(11) "Second item"
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
我正在使用PHP.
我有以下数组:
Array
(
[home] => 9
[pets] => 8
[dogs] => 7
[shampoo] => 7
[cover] => 6
)
Run Code Online (Sandbox Code Playgroud)
我想创建一个以逗号分隔的列表,它是:
home,pets,dogs,shampoo,cover
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试但给我空白字符串($words是数组):
$myWords = implode(',',$words[0]);
Run Code Online (Sandbox Code Playgroud)
我需要循环吗?
implode ×10
php ×10
arrays ×4
array-unique ×1
html ×1
iteration ×1
list ×1
mysqli ×1
object ×1
permutation ×1
str-replace ×1