【问题标题】:Getting array values from an imploded function从内爆函数中获取数组值
【发布时间】:2014-06-14 02:05:36
【问题描述】:

所以我有这个变量 $_GET 接收诸如

之类的值
set=QnVzaW5lc3M=|RmluYW5jZQ==

这些值使用 base64_encode() 进行 base64 编码,然后用分隔符“|”分隔。我正在使用 implode 函数来生成 set 变量的值。

现在的问题是,我怎样才能将 set 变量中的值放入一个数组中并进行 base64 解码?

欢迎提出任何建议。 我试过这个:-

$test = array();
$test = explode('|', $_GET['set']);
var_dump($test);

这会抛出不可用的值。 但这并没有什么不同。

【问题讨论】:

标签: php


【解决方案1】:
$data = 'QnVzaW5lc3M=|RmluYW5jZQ==';
$result = array_map(
    'base64_decode',
    explode('|', $data)
);
var_dump($result);

【讨论】:

    【解决方案2】:

    这应该可以使用 foreach:

    // Set the test data.
    $test_data = 'QnVzaW5lc3M=|RmluYW5jZQ==';
    
    // Explode the test data into an array.
    $test_array = explode('|', $test_data);
    
    // Roll through the test array & set final values.
    $final_values = array();
    foreach ($test_array as $test_value) {
      $final_values[] = base64_decode($test_value);
    }
    
    // Dump the output for debugging.
    echo '<pre>';
    print_r($final_values);
    echo '</pre>';
    

    输出是这样的:

    Array
    (
        [0] => Business
        [1] => Finance
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-22
      • 2013-04-04
      相关资源
      最近更新 更多