In PHP, how do you change the key of an array element?
$arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]);
$arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]);
Here’s a solution I wouldn’t be ashamed to show. Rationale Assume that we have an input array $input with N sub-arrays, as in your example. Each sub-array has Cn items, where n is its index inside $input, and its key is Kn. I will refer to the ith item of the nth sub-array as Vn,i. … Read more
Try this // file path $file=”orderdata.txt”; // REMEMBER TO MENTION THE CORRECT FILE WITH EXTENSION // open the file and get the resource handle with errors suppressed $handle = @fopen($file,’r’); // DONT USE @ while at development since it will suppress errors // array to hold our values $params = array(); if($handle) { // if … Read more
I think you member should be like this var members = [{unit:1,name: [“AA”, “AB”],userid:[“0001″,”0002”]}, {unit:2,name: [“BA”, “BB”],userid:[“0011″,”0012”]}]; var members = [{unit:1,name: [“AA”, “AB”],userid:[“0001″,”0002”]}, {unit:2,name: [“BA”, “BB”],userid:[“0011″,”0012”]}]; members.forEach(function(v,i){ if(v.unit==1) { console.log(v.name); } });