In my code in php 5 I need to access array key which have a dash in its name(case-ins). Is there any way to do that?
My code looks like this:
$count = 0;
foreach($par as $key){
foreach($key as $case-ins)
$count = $count+1;
....
}
Basically I need to get array size. I know I can probably use the count function, but right now the biggest problem I am dealing with is the dash. I have found on the internet something like ${case-ins}. but it didn't work. I can't change name of array key because it is actually argument from command line which I got using getopt.
Could you please help me with this? Or is there any other way around to count how many times was same argument used?
Thank you for all the answers :)
$case-insin that case is your choice. That is just the variable name, not the key itself. In fact, it wouldn't even be the key, it would be the value. (foreach($arr as $key => $value))$a = array('foo-bar' => 'b'); echo $a['foo-bar'];will outputb. I think you are confusing yourself here. The$case-insis the variable name. I might've understood it incorrectly, of course$case-ins, it throwssyntax error, unexpected '-'.$a-bwould at the very least mean that you want the subtractbfroma. When you type aforeach, you define the variable name, it doesn't matter the key nor the value. See the error. See it working.$valuecould be anything. Even an object. Take a look at this multi level array example: https://3v4l.org/3pSbA