not sure where the code snippet is placed, and where you are trying to access it from. A simple (but ugly) solution might simply be to set this array to be global.
Something like
$GLOBALS['leftids'] = $leftids;
and then from the other code use
global $leftids;
echo $leftids[0];