I created empty array and pushing val into it.
$var = array();
function printTag($tags) {
foreach($tags as $t) {
echo $t['token'] . "/" . $t['tag'] . " ";
if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
array_push($var, $t['token']) ;
}
}
echo "\n";
}
code looks fine for me but gives error:
array_push() expects parameter 1 to be array, null given in /var/www/html/postag/poscall.php on line 9
what is wrong here?
entire code:
<?php
// little helper function to print the results
include ("postag.php");
$var = array();
function printTag($tags) {
foreach($tags as $t) {
echo $t['token'] . "/" . $t['tag'] . " ";
if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
array_push($var, $t['token']) ;
}
}
echo "\n";
}
$tagger = new PosTagger('lexicon.txt');
$tags = $tagger->tag('The quick brown fox jumped over the lazy dog. this is really yummy and excellent pizza I have seen have really in love it it');
printTag($tags);
?>