What are the best practices for converting strings to numerical values for neural network training in PHP?

When training a neural network in PHP, it is important to convert strings to numerical values in order for the network to process the data effectively. One common approach is to use techniques like one-hot encoding or label encoding to convert categorical data into numerical format. This ensures that the neural network can interpret the data accurately during training.

// Example code for converting strings to numerical values using label encoding

$categories = ['cat', 'dog', 'bird', 'fish'];
$stringValue = 'dog';

$numericValue = array_search($stringValue, $categories);

echo $numericValue; // Output: 1