duanhan5388 2018-05-05 09:25
浏览 14
已采纳

php数组我有一个数组,我需要在数组中放置一些值

I have an function called send message

function sendMessage(){
    $content = array(
        "en" => 'value1'
    );
    $headings   = array(
        "en" => 'value2'
    );
    $hashes_array = array();

    fields = array(
        'app_id' => "31fe2347-5f39-4d9f-2222-79bf542f00f9",
        'included_segments' => array(
            'All'
        ),
        'data' => array(
            "foo" => "bar"
        ),
        'contents' => $content,
        'headings' => $headings,
        'url' => 'http://www.999999.in/view.php?id=[id]',
        'chrome_web_image'  => 'http://www.99999.in/admin/user_images/[userPic]',        
    );

And I have an array ready

Array(
    [id] => 498
    [value2] => యూట్యూబ్‌లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!
    [value1] => కొరటాల శివ దర్శకత్వం లో సూ...
    [value3] => 525722.jpg
) 

Now just I need to place array values in function

Please help me on this I tried all echo values

  • 写回答

2条回答 默认 最新

  • dongqiao8502 2018-05-05 09:33
    关注

    Pass the array as an argument to the function, then access the elements.

    function sendMessage($array) {
        $content      = array(
            "en" => $array['value1']
            );
        $headings   = array(
            "en" => $array['value2']
            );
        $hashes_array = array();
    
        $fields = array(
            'app_id' => "31fe2347-5f39-4d9f-2222-79bf542f00f9",
            'included_segments' => array(
                'All'
                ),
            'data' => array(
                "foo" => "bar"
                ),
            'contents' => $content,
            'headings' => $headings,
            'url' => 'http://www.999999.in/view.php?id=' . $array['id'],
            'chrome_web_image'  => 'http://www.99999.in/admin/user_images/' . $array['value3'],        
    
            );
        print_r($fields);
    }
    

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页