code:
$array[ ( preg_match( '/pdf-\d/', $key ) ? true : false ) + '[' + ( preg_match( '/pdf-total-\d/', $key ) ? true : false ) + ']' ]
output should be:
$array['pdf-1[pdf-total-1]']
Actually, you are using ternary operator:
preg_match( '/pdf-\d/', $key ) ? true : false
This returns true or false but never pdf-1 nor [pdf-total-1]
Maybe you want more something like this:
$array[
( preg_match( '/pdf-\d/', $key ) ? $key: false ) .
'[' . ( preg_match( '/pdf-total-\d/', $key ) ? $key: false ) . ']'
]
But it doesn't have much sense in any case because $key matches the first pattern or it matches the second
preg_match( '/pdf-\d/', $key )will return true or false, you dont need the? true : false, if you usepreg_match( '/pdf-(\d)/', $key )this will return one array with the (\d) foundpreg_matchreturns 0 when there is no match, 1 when a match is found, false when an error occurs.preg_matchwill not return the matched content!