Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-如何在数组中连接2个值_Php - Fatal编程技术网

PHP-如何在数组中连接2个值

PHP-如何在数组中连接2个值,php,Php,数组中有2个值,我想连接它们 请看上面的示例: <?php $a = array( 'test' => 'localhost', 'test2' => this->test .'/site' ); ?> 我想将valuetest与/site连接:localhost/site 我试过: 这个->测试 $a[“测试”] 试验 $test 他们中没有人工作。丑陋,但工作 $a = array( 'test' => $test = '

数组中有2个值,我想连接它们

请看上面的示例:

<?php
$a = array(
    'test' => 'localhost',
    'test2' => this->test .'/site'
);
?>

我想将valuetest/site连接:localhost/site
我试过:

  • 这个->测试
  • $a[“测试”]
  • 试验
  • $test
他们中没有人工作。

丑陋,但工作

$a = array(
    'test' => $test = 'localhost',
    'test2' => $test . '/site'
);


但是不能在数组上使用
$this->
,这是用于对象的。

例如,您可以使用
内爆
函数

<?php
$a = array(
    'test' => 'localhost',
    'test2' => '/site'
);
$result = implode($a);
?>


为什么不简单:
$a['test2']=$a['test']/地点'?你也可以考虑使用文本引用,比如<代码> %%Test%/Sturi'< /Cord>,然后有其他代码来解释:“杰克,你是对的,但是我想要一个数组中的所有变量,但是你的方法更好,这就是我所期望的。非常感谢。在数组中,我并不是只有两个变量,所以这个方法很好,但不适合这种情况。不管怎样,谢谢你们的回答。你们的方法很好,但我用的是杰西卡的解决方案。非常感谢。我用第二种方法,比较适合这种情况。谢谢你的回答!
$a = array('test' => 'localhost');
$a['test2'] => $a['test'] .'/site';
<?php
$a = array(
    'test' => 'localhost',
    'test2' => '/site'
);
$result = implode($a);
?>