Skip to content
Advertisement

PHP Return Array from function [closed]

I have a very simple web app that is capturing RFID tag reads and then submits it into the Database.

I have a function that was to pass the information through a filter and remove the duplicates and then return an array of unique tag reads.

The function looks like this

JavaScript

I then use Print_r to check the contents of the array to make sure it works.

When I run the code inside the function I do not get a result returned but when I run the following outside the function

JavaScript

It returns the values correctly ?

I am very new to PHP so I apologize if this question seems a little basic.

Advertisement

Answer

The function rfid returns a value which you could capture in a variable.

JavaScript

Note that you could shorten the function a bit:

JavaScript

Demo on https://3v4l.org/DY8Ts

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement