I am trying to pass array from shell_exec and want to access the array in bash file. I tried to research from many websites but did not find the proper solution for it. Plea
If your php variable $array is a php Array, you need to convert it to a string to do the call, eg:
shell_exec('sh get_countries.sh '.join(' ',$array));
Then your countries.sh
should be exactly what you gave as an example:
#!/bin/bash
declare -a myArray
myArray=("$@")
for arg in "${myArray[@]}"; do
echo "$arg"
done
Make sure you permit the file for execution with chmod a+rx countries.sh
.