While parsing a CSV file(I have used a Class found on Google), I ran into a problem. Here is an example of an array made from a .csv file(print_r):
Array
(
[0] => Array
(
[Site] => ViralNova
[Impressions] => 104719
[CTR] => 0.30%
[Clicks] => 311
[Average CPC] => $ 0.400
[CPM] => $ 1.19
[Conversion Rate] => 1.29%
[Actions] => 4
[CPA] => $ 31.100
[Spent] => $ 124.40
)
[1] => Array
(
[Site] => TMZ - Desktop
[Impressions] => 103276
[CTR] => 0.29%
[Clicks] => 295
[Average CPC] => $ 0.400
[CPM] => $ 1.14
[Conversion Rate] => 0.68%
[Actions] => 2
[CPA] => $ 59.000
[Spent] => $ 118.00
)
)
The Problem is that I cannot use the "Site" index. Whenever I try to, I get this notice:
<b>Notice</b>: Undefined index: Site in <b>C:\xampp\htdocs\panel\update\assets\php\core\core-ajax.php</b> on line <b>104</b><br />
Line 104 being:
print $data[0]['Site'];
Also,
print $data[0]['Impressions'];
or
print_r($data[0]);
works without any problem and I get the correct value/array.
Any ideas?
Thanks!!
Acc. to me your code is running fine.
this problem is occur when in loop in a point your index is missing.
to resolve this issue..
use this..
<?php
if($data[0]['Site']){
print $data[0]['Site'];
}
// Also
if($data[0]['Impressions']){
print print $data[0]['Impressions'];
}
?>
Related
I am using PHP WhatsApp Library. As per instructions I got my login and password. Upon using I am getting error:
] Logging in as 'SmartConnect Agent' (12334) tx <stream:features></stream:features>
tx <auth user="12334" mechanism="WAUTH-2"></auth>
rx <from s.whatsapp.net=""></from>
rx <stream:features></stream:features>
rx <challenge>fafa1216bdf3c4c4528e10d80b29c6026493682d</challenge>
tx <response>19d8120136e5897f38fe0904e54611cd8510f029bdd97f077f460faba15bc68cd0644e87ebf4b8288a143dc1914cb61bf4bfa2f17e0d7187afa8fcd18e69bb2b75d4f2da549c3d3c3facedd808bc</response>
rx <failure>
rx <not-authorized></not-authorized>
rx </failure>
Upon running blockchecker.php I get. Even same thing when I am retying to register by using registerTool.php
Wrong identity.
Array
(
[cc] => 92
[in] => 1234566
[lg] => en
[lc] => PK
[id] => >zv?+?????w!l?v?5b?
[mistyped] => 6
[network_radio_type] => 1
[simnum] => 1
[s] =>
[copiedrc] => 1
[hasinrc] => 1
[rcmatch] => 1
[pid] => 579
[extexist] => 1
[extstate] => 1
)
stdClass Object
(
[status] => fail
[reason] => incorrect
[sms_length] => 6
[voice_length] => 6
[sms_wait] => 0
[voice_wait] => 0
)
It generated multiple IDentity file of a same number. I removed all and it generated new password.
I have this simple code:
<?php
setlocale('LC_MONETARY', 'fr_CA.UTF-8');
echo money_format('%+#10n', '-4562.75834');
print_r(localeconv());
?>
Who normally should give -4 562,76 $. But the result is always this:
(4 562,76 $)
The output of localeconv():
Array
(
[decimal_point] => .
[thousands_sep] =>
[int_curr_symbol] => CAD
[currency_symbol] => $
[mon_decimal_point] => ,
[mon_thousands_sep] =>
[positive_sign] =>
[negative_sign] => -
[int_frac_digits] => 2
[frac_digits] => 2
[p_cs_precedes] => 0
[p_sep_by_space] => 1
[n_cs_precedes] => 0
[n_sep_by_space] => 1
[p_sign_posn] => 1
[n_sign_posn] => 0
[grouping] => Array
(
)
[mon_grouping] => Array
(
[0] => 3
[1] => 3
)
)
We can see that negative sign should be - but not ()
The locale on the server (which is Debian 7), is installed:
# locale-gen
Generating locales (this might take a while)...
en_CA.UTF-8... done
fr_CA.ISO-8859-1... done
fr_CA.UTF-8... done
Generation complete.
I have tried with PHP 5.4.45 and 5.6.17
You have put the LC_MONETARY between single quotes.
It needs to live as a const variable which is set as not in quotes.
setlocale(LC_MONETARY, 'fr_CA.UTF-8');
Hi I need to parse the ini file shown below using php, which is basically created using Qt QSettings, I have tried the code here, but seems the INI file are different format there.
Is it possible to parse INI file in below format using PHP ?
[General]
Address=
Email=test#gmail.com
Password=123$
Sync=0
Loggedin=1
[Drives]
1\drive=/
1\free=281
1\size=908
2\drive=/media/New_Volume
2\free=6
2\size=7
3\drive=/media/sdb2
3\free=906
3\size=916
size=2
[Cam]
1\detection=0
1\Area.height=2.4
1\Area.width=9.5
2\detection=0
2\Area.height=2.4
2\Area.width=9.5
3\detection=0
3\Area.height=2.4
3\Area.width=9.5
size=2
Update:
Actually the above ini was working as said in below answer, and my actyual ini contains the $ symbol, that was creating the problem.
[General]
Address=
Email=test#gmail.com
Password=123$
Sync=0
Loggedin=1
[Drives]
1\drive=/
1\free=281
1\size=908
2\drive=/media/New_Volume
2\free=6
2\size=7
3\drive=/media/sdb2
3\free=906
3\size=916
size=2
[Cam]
1\detection=0
1\Area.height=2.4
1\Area.width=9.5
2\detection=0
2\Area.height=2.4
2\Area.width=9.5
3\detection=0
3\Area.height=2.4
3\Area.width=9.5
size=2
And seems I have to escape the $ symbol.
It works just fine, take a look at the php code while the .ini file stays exactly as you have it.
$ini_array = parse_ini_file("settings.ini",true);
print_r($ini_array);
//will output
Array
(
[General] => Array
(
[Address] =>
[Email] => test#gmail.com
[Password] => 123$ // note the $ sign in value here
[Sync] => 0
[Loggedin] => 1
)
[Drives] => Array
(
[1\drive] => /
[1\free] => 281
[1\size] => 908
[2\drive] => /media/New_Volume
[2\free] => 6
[2\size] => 7
[3\drive] => /media/sdb2
[3\free] => 906
[3\size] => 916
[size] => 2
)
[Cam] => Array
(
[1\detection] => 0
[1\Area.height] => 2.4
[1\Area.width] => 9.5
[2\detection] => 0
[2\Area.height] => 2.4
[2\Area.width] => 9.5
[3\detection] => 0
[3\Area.height] => 2.4
[3\Area.width] => 9.5
[size] => 2
)
)
i have an array in which each key it has another array.
What i want to do is to store those values in different arrays.
For example, the original array looks like the following:
Array
(
[0] => Array
(
[concurso] => 2758
[R1] => 12
[R2] => 20
[R3] => 33
[R4] => 46
[R5] => 50
[R6] => 51
[R7] => 54
)
[1] => Array
(
[concurso] => 2759
[R1] => 12
[R2] => 15
[R3] => 31
[R4] => 50
[R5] => 54
[R6] => 55
[R7] => 11
)
[2] => Array
(
[concurso] => 2760
[R1] => 4
[R2] => 11
[R3] => 12
[R4] => 40
[R5] => 45
[R6] => 51
[R7] => 55
)
.
.
.
[29] => Array
(
[concurso] => 2787
[R1] => 3
[R2] => 5
[R3] => 19
[R4] => 24
[R5] => 28
[R6] => 30
[R7] => 15
)
)
And for each key i want to store the corresponding values in different arrays (where 'concurso' will be the key of each new array and its corresponding Rn value):
R1:
Array
(
[2758] => 12
[2759] => 12
[2760] => 4
...
[2787] => 3
)
R2:
Array
(
[2758] => 20
[2759] => 15
[2760] => 11
...
[2787] => 5
)
R3:
Array
(
[2758] => 33
[2759] => 31
[2760] => 12
...
[2787] => 19
)
R4:
Array
(
[2758] => 46
[2759] => 50
[2760] => 40
...
[2787] => 24
)
R5:
Array
(
[2758] => 50
[2759] => 54
[2760] => 45
...
[2787] => 28
)
R6:
Array
(
[2758] => 51
[2759] => 55
[2760] => 51
...
[2787] => 30
)
...
Rn:
How do i achieve this? I guess i need to create variable names dynamically, since the number of elements of a given array may change depending on the data retrieved.
What do you suggest?
I am trying this code but no luck so far:
$ultimos_sorteos_m,true); //this is the big array shown above
foreach($ultimos_sorteos_m as $key1 => $last_sorteos){
$contador=count($last_sorteos); //how many items the current sub-array has
$k=1; //an index
echo '<p>the number of items is '.$contador.'</p>';
foreach($last_sorteos as $key=>$valor){
if($key=='concurso'){
$concurso=$valor;
echo 'concurso: '.$concurso.' <br>'; //to get the 'concurso' that will work as a key for the other arrays
}
//storing here the rest of the values
if(substr( $key, 0, 1 ) === "R" && substr($key, 1, 1)===$k){
//i don't know here how to store the values in different arrays
echo 'storing value: '.$valor.'<br>';
$Ritems[$concurso]=$valor; //the problem is that only store the last value
}
}
}
If you want to know why, I want it this way in order to graph those data by using the phpgraphlib graphing library. It will be a graph showing different lines.
Try this : This creates variable names dynamically so you dont need to know the number for R1,R2,R3 etc elements you have
<?php
foreach($ultimos_sorteos_m[0] as $key1 => $last_sorteos){
$$key1 = array_column($ultimos_sorteos_m, $key1 , 'concurso'); // This is a dynamic variable name. See http://php.net/manual/en/language.variables.variable.php
}
var_dump($R1);
var_dump($R2);
?>
Please comment if you see a problem. Thanks!
Like this?
foreach($orig_array[0] as $key => $_)
$new_array[$key] = array_column($orig_array, $key, 'concurso');
array_column
shim for php < 5.5
If you're absolutely sure you need R1, R2 as variables (you don't), you can extract() the array afterwards.
You can use array_column. Try this if your PHP version 5.5+
$R1 = array_column($arr, 'R1', 'concurso');
.
.
.
$R7 = array_column($arr, 'R7', 'concurso');
I want to be able to extract the output of [HostName] from this array in PHP. Thank you!
Array
(
[Protocol] => 17
[HostName] => [HG] JAILBREAK #1 - HeLLsGamers.com | 30+ LR's | FastDL
[Map] => ba_jail_hellsgamers_fx6
[ModDir] => cstrike
[ModDesc] => Counter-Strike: Source
[AppID] => 240
[Players] => 12
[MaxPlayers] => 64
[Bots] => 0
[Dedicated] => d
[Os] => l
[Password] =>
[Secure] => 1
[Version] => 1.0.0.75
[GamePort] => 27015
[ServerID] => -682722125
[GameTags] => HLstatsX:CE,alltalk,bunnyhopping,cool,drugs,free,gameme,gang,hellsgamers,hg,increased_maxplayers,jail,jailbr,nostats,startmoney
)
Like this:
echo $Array[HostName]; // output: [HG] JAILBREAK #1 - HeLLsGamers.com | 30+ LR's | FastDL
where $Array is the array you printed and copied here.
I recommend you start reading stuff from php.net - as this is the most basic thing you can do.
Thats the most simplest question .........
Just use this
echo $Your_array[HostName];