用数组键替换字符串中的值

时间:2015-12-11 21:09:55

标签: php arrays

我试图用数组键替换数组中的值:

示例1:

Array
(
    [cid] => 1-category-title
    [slug] => 100-article-title
)

我的字符串:products/{:cid}/{:slug}

我试图替换它:products/1-category-title/100-article-title

示例2:

Array
(
    [cid] => 1-category-title
    [slug] => 100-article-title
    [page_id] => 5
)

我的字符串:products/{:cid}/{:slug}

我试图替换它:products/1-category-title/100-article-title?page_id=5

示例3:

Array
(
    [cid] => 1-category-title
    [slug] => 100-article-title
    [page_id] => 5
    [format] => json 
)

我的字符串:products/{:cid}/{:slug}

我试图替换它:products/1-category-title/100-article-title?page_id=5&format=json

1 个答案:

答案 0 :(得分:1)